Unix Technical Forum

selective sql request

This is a discussion on selective sql request within the SQL Server forums, part of the Microsoft SQL Server category; --> Hi, I've got the following Stored Procedure CREATE PROCEDURE pr_Admin_GetCtrlFields --Get the control fields, detail or flow according to ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 09:09 AM
Sam
 
Posts: n/a
Default selective sql request

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 09:09 AM
David Portas
 
Posts: n/a
Default Re: selective sql request

COALESCE(viewtable, roottable) AS viewtable

--
David Portas
SQL Server MVP
--

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 09:09 AM
Sam
 
Posts: n/a
Default Re: selective sql request

Thx !

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 09:10 AM
Erland Sommarskog
 
Posts: n/a
Default Re: selective sql request

Sam (samuel.berthelot@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, esquel@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:03 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com