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
 AND OR

Author  Topic 

1troy123
Starting Member

1 Post

Posted - 2012-04-30 : 14:20:53
HI im hopeing to write a query that uses both AND & OR in away that means i dont have to work with all the possible out comes is this possible

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-30 : 14:23:05
its possible
something like


...
WHERE (Field1=@Param1 OR @Param1 IS NULL)
AND (Field2=@param2 OR @Param2 IS NULL)
...


make sure you set default values of parameters to NULL
Also for large datasets performance of above logic can be bad due to inefficient query plan formation.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -