I have 4 case statements that are exactly the same CASE criteria, but they all have different THEN/ELSE statements.
Is it possible to do this all in one, or do I need to separate these all out and copy and paste the code multiple times?
,CASE WHEN lm.Id IN ('1','2','3') THEN lm.name ELSE lm.Desc END AS [Column1]
,CASE WHEN lm.Id IN ('1','2','3') THEN '3' ELSE '1' END AS [Column2]
,CASE WHEN lm.Id IN ('1','2','3') THEN 'True' ELSE 'False' END AS [Column3]
Is it possible to do this with less code?
I don’t think this is possible in strict SQL. Some DB engines may support it as an extension. You could probably accomplish functionally the same thing through some other mechanism, though… possibly with a JOIN, or a UNION.