I have some T-SQL code using multiple if statements (about 100) as below. If the first IF statement condition evaluates to TRUE it still evaluates the rest of 99 statements.
IF(@check = 'abc') SET @var1 = @value
IF(@check = 'def') SET @var2 = @value
IF(@check = 'ghi') SET @var3 = @value
IF(@check = 'jkl') SET @var4 = @value
IF(@check = 'mno') SET @var5 = @value
…
…
I want to convert these to use a CASE Expression. for e.g
CASE @check
WHEN 'abc' THEN SET @var1 = @value
WHEN 'def' THEN SET @var2 = @value
WHEN 'ghi' THEN SET @var3 = @value
WHEN 'jkl' THEN SET @var4 = @value
WHEN 'mno' THEN SET @var5 = @value
…
…
END
However, I am not able to do so, and I get a SQL error that says I cannot use SET within a CASE Expression.
Does anyone have any ideas how I can achieve this? Thanks!
SET @var1 = CASE WHEN ... THEN ... END
? – Thea@check
? – HartfieldIF...ELSE
. – Southbound