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 |
CrazyT
Yak Posting Veteran
73 Posts |
Posted - 2010-06-25 : 16:53:54
|
How do i do i case statement in a where clausesomething like where product = 1 case somethingand product = 2 I get error near case |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-06-25 : 17:25:37
|
quote: Originally posted by CrazyT How do i do i case statement in a where clausesomething like where product = 1 AND CASE WHEN Boolean_expression THEN result_expression [ ...n ] [ ELSE else_result_expression ] ENDand product = 2 I get error near case
|
 |
|
CrazyT
Yak Posting Veteran
73 Posts |
Posted - 2010-06-25 : 17:31:20
|
kind of need something like this -- when the length of password is > 0 then add where password = @password to the where statement else dontthis works and (Case WHEN LEN(ISNULL(Password,''))>0 then Password else Password End)= @Passwordbut doesnt really do what i want |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-06-26 : 08:00:34
|
Why do you need a case statement?It can be easily achieved by using a where clause.Something like thisdeclare @param as varchar(40)='test'select * from yourtable where (len(@param)>0 and Password=@param) Limitations live only in our minds. But if we use our imaginations, our possibilities become limitless. PBUH |
 |
|
CrazyT
Yak Posting Veteran
73 Posts |
Posted - 2010-06-28 : 11:41:44
|
Problem is this:The database has some string.empty cases and some null entires for the password field so i dont want to even consider the "and passowrd = @password" in the where clause if @password is null. so thats the reason for the case statementi guess i can do it with an if/then and have both complete queries in it. didnt know if there was a better way to just not include the "and passowrd = @password" |
 |
|
X002548
Not Just a Number
15586 Posts |
|
|
|
|