|
Home > Archive > Microsoft SQL Server forum > June 2005 > selective sql request
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
selective sql request
|
|
|
| Hi,
I've got the following Stored Procedure
CREATE PROCEDURE pr_Admin_GetCtrlFiel
ds
--Get the control fields, detail or flow according to the ModeID
parameter
@QueryID int,
@ModeID int
AS
SELECT FieldID, FieldName, EntryInfo, ControlTypeID,ViewFi
eldTypeID,
ViewTable, ViewField,
F.SortOrder, InsertField, UpdateField, FieldTabId, ModeId
FROM Fields F, Queries
WHERE F.QueryID = @QueryID
AND ControlTypeID <> NULL
AND ModeID = @ModeID
ORDER BY F.SortOrder ASC
GO
[Fields] and [Queries] are linked by a field called {QueryID}.
[Queries] contain a field called {RootTable}, and what I want to do is:
If ViewTable is NULL then I select {RootTable} as ViewTable, otherwise
I select ViewTable as I'm currentely doing it.
So how can I introduce this condition in my Select statement?
Thx
| |
| David Portas 2005-06-24, 7:23 am |
| COALESCE(viewtable, roottable) AS viewtable
--
David Portas
SQL Server MVP
--
| |
|
|
| Erland Sommarskog 2005-06-24, 8:23 pm |
| Sam (samuel.berthelot@voila.fr) writes:
> Hi,
> I've got the following Stored Procedure
>
> CREATE PROCEDURE pr_Admin_GetCtrlFiel
ds
> --Get the control fields, detail or flow according to the ModeID
> parameter
> @QueryID int,
> @ModeID int
> AS
>
> SELECT FieldID, FieldName, EntryInfo, ControlTypeID,ViewFi
eldTypeID,
> ViewTable, ViewField,
> F.SortOrder, InsertField, UpdateField, FieldTabId, ModeId
> FROM Fields F, Queries
>
> WHERE F.QueryID = @QueryID
> AND ControlTypeID <> NULL
Beware! This is most certainly not what you want. This condition
will never evaulate to TRUE. Use IS NOT NULL instead.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp
|
|
|
|
|