471,108 Members | 1,338 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,108 software developers and data experts.

selective sql request

Sam
Hi,
I've got the following Stored Procedure

CREATE PROCEDURE pr_Admin_GetCtrlFields
--Get the control fields, detail or flow according to the ModeID
parameter
@QueryID int,
@ModeID int
AS

SELECT FieldID, FieldName, EntryInfo, ControlTypeID,ViewFieldTypeID,
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

Jul 23 '05 #1
3 1050
COALESCE(viewtable, roottable) AS viewtable

--
David Portas
SQL Server MVP
--

Jul 23 '05 #2
Sam
Thx !

Jul 23 '05 #3
Sam (sa**************@voila.fr) writes:
Hi,
I've got the following Stored Procedure

CREATE PROCEDURE pr_Admin_GetCtrlFields
--Get the control fields, detail or flow according to the ModeID
parameter
@QueryID int,
@ModeID int
AS

SELECT FieldID, FieldName, EntryInfo, ControlTypeID,ViewFieldTypeID,
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, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Solitus | last post: by
1 post views Thread by aman909 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.