Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 store procedures and if statements

Author  Topic 

csphard
Posting Yak Master

113 Posts

Posted - 2005-09-15 : 14:32:17
I have a screen where I could pass 8 parameters.
section, (3 digit number)
division, (3 digit number)
bureau, (3 digit number)
evaluation type (annual,probation,all)
from date mm/yyyy
to date mm/yyyy
However the following 4 of those paramters are optional.
section, (3 digit number)
division, (3 digit number)
bureau, (3 digit number)
evaluation type (annual,probation,all)


How do I build if statements into my store procedure
to account for these if they are present

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2005-09-16 : 00:16:36
DECLARE @section = NULL, @division = NULL, etc

You then need to test for NULL in your WHERE clauses.

WHERE (@section IS NULL OR section = @section) AND (@division IS NULL OR division = @division)


MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page
   

- Advertisement -