i need in SQL the equivalent C# code for
int caseSwitch = 1;
switch (caseSwitch)
{
case 1:
case 2:
case 3:
case 4:
    Console.WriteLine("x");
    break;
default:
    Console.WriteLine("Default case");
    break;
}
i have multiple conditions and same result and i don't want to write all code
case when cond1 then result1
     when cond2 then result1
     when cond3 then result1
     ....
     end
any ideas ? thanks
Something like this:
DECLARE @caseSwitch INT=1
SELECT
    CASE WHEN @caseSwitch IN (1,2,3,4)
    THEN 'x'
    ELSE 'Default case'
END
In a table select. It would be something like this:
DECLARE @caseSwich INT=1
SELECT
    (
       CASE WHEN @caseSwich IN (1,2,3,4)
          THEN 'x'
          ELSE 'Default case'
       END
    ) AS someColumn
FROM
    yourTable
                        DECLARE @i INT
SET @i = 2
SELECT CASE WHEN @i IN (1,2,3,4) THEN 'Hi' ELSE 'HiHi' END AS Result
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With