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 |
|
Broodmdh
Starting Member
2 Posts |
Posted - 2007-07-31 : 12:51:01
|
I am trying to write a WHERE clause that utilizes CASE (or IF), but I'm not having any luck. I'm trying to manage something like the following:...WHERE x.Var1 = @var1AND (CASE @var2 WHEN 'Y' THEN x.Var3 >= @Var3 END WHEN 'N' THEN x.Var3 > @Var3 END END)AND ... Is this sort of thing possible? I haven't been able to get it to work so far. |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2007-07-31 : 13:00:27
|
Maybe:...WHERE x.Var1 = @var1 AND x.Var3 >= CASE @var2 WHEN 'Y' THEN @Var3 ELSE @Var3 + 1 END AND ... |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Broodmdh
Starting Member
2 Posts |
Posted - 2007-07-31 : 13:21:24
|
Ifor's suggestion worked well. How would you make this work for something like the following:AND x.Var4 INCASE @Var4 WHEN 'A' THEN (1) WHEN 'I' THEN (0) WHEN 'B' THEN (0,1)END This throws the following error for me: "Incorrect syntax near the keyword 'CASE'". |
 |
|
|
|
|
|