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.
Author |
Topic |
LearningSQLKid
Yak Posting Veteran
51 Posts |
Posted - 2012-02-06 : 16:22:18
|
Hi GuysAny idea how can i use/not use where clause based on some conditionFor exampleIf variable value=1 then use query with where clause other wise exclude where clause from the query and executeThe easy way is to repeat the same query in if else block but that causes the repetition and if the quries are big and the difference is just the where clause then its not that the good way .... is that possible to exclude where clause based on some conditionThanks in Advance..Select Knowledge from LearningProcess |
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2012-02-06 : 16:28:42
|
[CODE]select <whatever>from MyTablewhere (@Var = 1 AND <Other conditions>)OR @Var <> 1[/CODE]HTH=================================================Men shout to avoid listening to one another. -Miguel de Unamuno |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-06 : 16:58:46
|
wont this suffice?select <whatever>from MyTablewhere <Other conditions>OR @Var <> 1 ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|