Click here to Skip to main content
15,908,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table like

Id Name Group
100 venki
100 suresh
105 ramu
101 gopi
105 pavan
119 rama
120 meghana
125 mounika
130 Jyothi

I need to show the values in group column..below is the selection criteria

If ID=100 THEN 'Group-A'
ID=105 THEN 'Group-B'
All Other values = 'Group-C'


Can anyone please help me how to write CASE statement for this requirement??

Thanks in Advance
SQL
<pre lang="SQL"><pre lang="SQL"><pre lang="SQL">


What I have tried:

I tried like below

CASE
WHEN ID =100 THEN 'GROUP-A'
WHEN ID= 105 THEN 'GROUP-B'
....
END

But I don't know how to write CASE for "All Other Values".
Posted
Updated 27-Apr-16 1:15am

Next time read the documentation documentation[^].
SQL
CASE 
WHEN ID =100 THEN 'GROUP-A' 
WHEN ID= 105 THEN 'GROUP-B'
ELSE 'Group-C'
END
 
Share this answer
 
Comments
OriginalGriff 27-Apr-16 7:17am    
Simple, and to the point! :thumbsup:
Member 11931581 27-Apr-16 7:35am    
Thank you!!
try
SQL
SELECT 
  *
   ,Case 
         WHEN  ID =100 THEN 'GROUP-A' 
         WHEN  ID= 105 THEN 'GROUP-B'
         ELSE  'Unknown'
   END
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900