DECLARE @TestVal int SET @TestVal = 5 SELECT CASE WHEN @TestVal <=3 THEN 'Top 3' ELSE 'Other' END
I saw this sample code online but I couldn’t find an example where there was no expression and it had more than one WHEN, so I am wondering if this type of thing is OK:
DECLARE @TestVal int SET @TestVal = 5 SELECT CASE WHEN @TestVal <=3 THEN 'Top 3' WHEN (select ...) = 1 THEN 'Other Value' WHEN (select ...) = 2 THEN 'Other Value 2' ELSE 'Other' END
Or do I need to say CASE WHEN for each line?
Case takes the following form
Edit
This assumes your using Microsoft SQL Server other DBMS might be different