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 |
|
jggtz
Starting Member
32 Posts |
Posted - 2008-06-18 : 21:52:08
|
| MS SQL 2005I hope this is clearHow can I conditionate a WHERE in a SELECT using an input parameter?This is,If the parameter is 1 then use WHERE field1=AIf the parameter is 2 then use WHERE field1=A AND field2=BThanksJG |
|
|
Goldmember
Starting Member
9 Posts |
Posted - 2008-06-18 : 23:39:47
|
| Use the IF-Else Conditional programming logicFor exampleIF(paramater1 = whatever value you expect)WHERE field1=AELSE(paramater2 = whatever value you expect)WHERE field2=Btry something similar to thisIt will be difficult for the WHERE clause to use the AND boolean operator. I don't think it works, but it might if you create another IF ELSE STATEMENT after which inputs the second parameter using the second field. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-19 : 02:12:48
|
| [code]WHERE field1=AAND (@Parameter<>2 OR (@Parameter=2 AND field2=B))[/code] |
 |
|
|
jggtz
Starting Member
32 Posts |
Posted - 2008-06-19 : 03:27:13
|
quote: Originally posted by visakh16
WHERE field1=AAND (@Parameter<>2 OR (@Parameter=2 AND field2=B))
That's it!Thanks |
 |
|
|
|
|
|