The example you provided should work. You can assign variables from the case statement. Just pretend that the entire CASE..WHEN..THEN..ELSE..END block is a field. Here is a general example:
declare @string1 nvarchar(100) = null ,@string2 nvarchar(100) = null ; select top 1 @string1 = case when 1=1 then 'yes' else 'no' end ,@string2 = case when 1=0 then 'yes' else 'no' end print 'string1 = ' + @string1 print 'string2 = ' + @string2
gives:
string1 = yes string2 = no
Can you tell us what specific errors you get?
JosephStyons
source share