SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Case When Return Multiple Output
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

daniel50096230
Yak Posting Veteran

Malaysia
96 Posts

Posted - 01/14/2013 :  23:11:35  Show Profile  Reply with Quote
I have my sql as below:

SELECT
Case
When Product_ID = 'A' Then 'Active'
When Product_ID = 'B' Then 'Obselete'
End As Description
Case
When Product_ID = 'A' Then 'Good'
When Product_ID = 'B' Then 'Bad'
End As Condition
FROM Table_A


Since the two Case condition is the same, is there possible to make it into one?

Eg. Case When Product_ID = 'A' THEN 'Active' As Description, 'Good' As Condition

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 01/15/2013 :  00:07:39  Show Profile  Reply with Quote
Nope. CASE is not a control flow statement but its just a conditional expression.
if you really need to do it you need this

SELECT 'Active' AS Description,'Good' AS Condition
FROM Table_A
WHERE Product_ID = 'A'
UNION ALL
SELECT 'Obselete','Bad'
FROM Table_A
WHERE Product_ID = 'B'



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000