title: SQL Case Issue Setting Variable
body: <p>Why is it that I can't do the below script and how would I go about fixing it? I get the error <code>Inccorect syntax near '='</code>. I was doing it using <code>...= 1 THEN 'D' ELSE '' END as Aset</code> but I need to check Aset and Bset in the third Case so I declared Aset and Bset instead.</p>
  
  <pre><code>declare @Aset varchar(10)
  declare @Bset varchar(10)
  UPDATE m
      SET m.new_name = m.new_name + ' ' + @ASet + AndSet + @BSet + ' Type'
  FROM contactMaster m
  inner join contact c on 
      m.contactid = c.contactid
       CROSS APPLY (
           SELECT CASE @Aset WHEN (c.category1|
                              c.category2|
                              c.category3|
                              c.category4) = 1 THEN 'C' ELSE '' End
                 ,CASE @Bset WHEN (c.category5|
                              c.category6|
                              c.category7|
                              c.category8) = 1 THEN 'D' ELSE '' END
                  ,CASE WHEN @BSet = 'D' and  @ASet  = 'C' THEN ' &amp; ' ELSE '' END AS AndSet
       ) AS CA1
  </code></pre>