CASE statement within WHERE statement

Posted by niao on Stack Overflow See other posts from Stack Overflow or by niao
Published on 2010-05-21T07:26:47Z Indexed on 2010/05/21 7:30 UTC
Read the original article Hit count: 251

Filed under:
|

Greetings, I would like to include CASE Statement inside my where statement as follows:

SELECT a1.ROWGUID FROM Table1 a1
INNER JOIN Table2 a2 on a1.ROWGUID=a2.Table1ROWGUID
WHERE a1.Title='title' 
AND (CASE WHEN @variable is not null THEN a1.ROWGUID in (SELECT * FROM #TempTable))

However, this 'CASE' statement does not work inside 'WHERE' statement. How can I do it correct?

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server