Using a case statement to set the values of declared variables

118 Views Asked by At

I wanted to know if its possible to set the values of declared variables by using a case statement. example:

CASE
    WHEN fieldValue ='stringValue1' THEN SET @DeclaredVar1 = 100 
END
1

There are 1 best solutions below

2
On BEST ANSWER

You are on the right track, but syntax you've used is incorrect. It should be

select @DeclaredVar1 = case 
                         when fieldValue ='stringValue1' then 100 
                         else --another option here-- 
                       end