By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,766 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,766 IT Pros & Developers. It's quick & easy.

Multiple results from a Case statement in a Where clause

P: 2
Hello,

I am trying to return multiple values as the CASE result embedded in a WHERE clause.
This sample code, though it throws a syntax error, should give an idea what I am trying to accomplish.

Any ideas or advice to obtain the desired result would be greatly appreciated.

DECLARE @i INT
SET @i =1
WHILE @i < 3
BEGIN
SELECT a.CompanyName AS 'Company' FROM Company AS a
WHERE a.CompanyCode IN
(CASE
WHEN @i = 1 THEN 'A','B','C'
WHEN @i = 2 THEN 'X','Y','Z'
END
)
SET @i = @i+1
END
Sep 4 '09 #1
Share this Question
Share on Google+
2 Replies


ck9663
Expert 2.5K+
P: 2,878
try rewriting your WHERE clause like...

Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE (@i = 1 and 
  3. a.CompanyCode IN ('A','B','C')) or 
  4. (@i = 2 and
  5. a.CompanyCode IN ('X','Y','Z')
  6.  
  7.  
Good luck!!!

--- CK
Sep 5 '09 #2

P: 2
Thanks.
I had that feeling of being too close to the forest to see the trees
Sep 5 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.