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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 CASE clause in WHERE

Author  Topic 

sqlpal2009
Yak Posting Veteran

58 Posts

Posted - 2009-08-20 : 12:33:42
Hello All,

How should eliminate the error in below code?

If the @SeqID parameter is NULL then I want sequenceID = 1 else @SeqID and 1.


SELECT *
FROM T
WHERE Ports = @ProtName AND
CASE WHEN ISNULL(@SeqID,'') = '' THEN sequenceID = 1 ELSE sequenceID IN (@SeqID, 1) END


Thanks,
-S

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-20 : 12:48:26
SELECT *
FROM T
WHERE Ports = @ProtName AND
sequenceID IN (isnull(@SeqID,1), 1)



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

sqlpal2009
Yak Posting Veteran

58 Posts

Posted - 2009-08-20 : 12:55:15
If @SeqID is not null then sequenceID IN (@SeqID, 1) else sequenceID = 1
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-20 : 12:58:07
Yes!?


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -