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 |
kensai
Posting Yak Master
172 Posts |
Posted - 2008-06-23 : 09:06:54
|
Is anything similar to this possible without writing whole query in every begin block or without dynamic sql:proc(@arg1 bit)select * from table where x=y if @arg1 = 1 begin and when a=bendorder by date |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-06-23 : 09:18:23
|
SELECT *FROM TableWHERE x = y AND (A = B OR @arg1 = 0)order by date E 12°55'05.25"N 56°04'39.16" |
 |
|
kensai
Posting Yak Master
172 Posts |
Posted - 2008-06-24 : 04:03:36
|
Thank you Peso. |
 |
|
kensai
Posting Yak Master
172 Posts |
Posted - 2008-06-24 : 04:27:00
|
Ok what about multiple condition, like:select * from table where x=ycase @argwhen 1 then and where a=1when 2 then and where a=2end caseis this possible? |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-24 : 04:30:59
|
apply similar logicselect * from table where x=yand a=@arg |
 |
|
kensai
Posting Yak Master
172 Posts |
Posted - 2008-06-24 : 05:53:37
|
quote: Originally posted by visakh16 apply similar logicselect * from table where x=yand a=@arg
Haha sorry my example was stupid I just realized that. This would be better:select * from table where x=ycase @argwhen 1 then and where a=bwhen 2 then and where a=cend caseI know it doesn't make much sense in the example but it's the principle I'd like learn, if possible that is. |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-24 : 05:55:45
|
select * from table where x=yand (a=b or @arg<>1)and (a=c and @arg<>2)... |
 |
|
|
|
|