Question : Sql CAse in SP

I have  a sp that I am running a long query and need to use case and I am getting a syntax error.
Incorrect syntax near the keyword 'CASE'.


--check status
Select .......
and x = 0  
and y = 1
CASE When @QT= 'A'
   Then
        (and B = 1)
    End

Answer : Sql CAse in SP

Try something like this syntax, you can't use the Case like you had it.  It will be true and return rows ONLY when the column B is equal to 1 when the @QT variable is equal to 'A'.  If you want it to always return the rows when @QT <> 'A' then use this instead "and B = (CASE When @QT= 'A' Then 1 Else B End)"
1:
2:
3:
4:
5:
--check status
Select ....
where x = 0
and y = 1
and B = (CASE When @QT= 'A' Then 1 End)
Random Solutions  
 
programming4us programming4us