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
 General SQL Server Forums
 New to SQL Server Programming
 option to not split stored procedure

Author  Topic 

andrewcw
Posting Yak Master

133 Posts

Posted - 2012-02-07 : 23:04:11
Hi all

One of my 7 input parameters has an integer value, where the value if 0 means all values for that field.

Its possible to split the query

if @theIntegerValue =0

Select - big long query with where ...

else

Select - big long query with where AND (theVal= @theIntegerValue)

This is probably a familiar pattern, but I cant think of a way to get around the issue as I can with a like '%@MightBeEmptyString' to avoid making the if statement

Thanks !

andrewcw

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-02-08 : 00:07:26
Use one query and add this to the end:

where ... AND (@theIntegerValue = 0 OR theVal = @theIntegerValue)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2012-02-08 : 03:33:24
Use Dynamic SQL ?
Go to Top of Page
   

- Advertisement -