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 2008 Forums
 Transact-SQL (2008)
 Case When Return Multiple Output

Author  Topic 

daniel50096230
Yak Posting Veteran

99 Posts

Posted - 2013-01-14 : 23:11:35
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

52326 Posts

Posted - 2013-01-15 : 00:07:39
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
   

- Advertisement -