SQL Server : set a variable in CASE statement

You can use

SET @StartDateQ1 = CASE @q1
                     WHEN 1 THEN '20130401'
                   END 

to set the value of a single variable according to a CASE expression.

If your real logic is more complicated (e.g. need to set multiple variables inside a condition) look at IF ... ELSE instead.

CASE is an expression not a flow of control construct.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)