In C# we can write
switch(num)
{
case 0:
case 1: // do something; break;
case 2:
............
...........
case n: // do something break;
default: //do something; break;
}
How can I achieve the similar kind of stuff in SQL SERVER ?
I am not talking about the simple way of writing CASE in SQL SERVER. I am talking about if I need to perform the same king of operation in 2 or more case's as what I showed in C# code snippet, how to do the similar kind of stuff in SQL's CASE?
EDIT:
I got some nice answers from here already. How can I convert the following
SELECT CASE
WHEN [A]= num THEN '-' ELSE '' END [A],
CASE WHEN [B]= num THEN '-' ELSE '' END [B],
CASE WHEN [C]= num THEN '-' ELSE '' END [C],
CASE WHEN [D]= num THEN '-' ELSE '' END [D]
...into something like:
SELECT CASE WHEN [A],
CASE WHEN [B],
CASE WHEN [C],
CASE WHEN [D] = num THEN '-' ELSE '' END [A] or [B] or [C] or [D]
Actually I need this in a PIVOT query. Last night I solved the problem. But I am not convinced with this way of writing. Because everytime, I am doing the same thing. So is there any better way of presenting this?