title: Variable in query doesn't work
body: <p>I'm facing some problem with a SQL query, I'm creating a variable :</p>
  
  <pre><code> declare @material varchar(500)
   declare @typ varchar(200)
   declare @strsql varchar(max)
   set @typ = 'papier'
  
   select @material = (SELECT + rtrim(ltrim([grupa])) + ','
                       FROM [test].[dbo].[GT] 
                       WHERE (typ = @typ) FOR XML PATH(''))
   set @material =  left(@material, len(@material)-1)
   set @material  = replace(@material, ',' ,''',''')
   set @material = '''' + @material + ''''
  
   select @material
  </code></pre>
  
  <p>The output from variable is :</p>
  
  <pre><code>'test','test2'
  </code></pre>
  
  <p>And here is a little part of my main code :</p>
  
  <pre><code> SELECT
       Number,
       isnull(sum((case 
                      when [Group] in ('test','test2') 
                         then isnull(cast([Quantity] as int), 0) 
                   end)), 0) as other
   FROM
       [dbo].[test-table]
  </code></pre>
  
  <p>which works correct but when I'm trying to do this like that :</p>
  
  <pre><code> SELECT
       Number,
       isnull(sum((case 
                      when [Group] in (@material) 
                         then isnull(cast([Quantity] as int), 0) 
                    end)), 0) as other
   FROM
       [dbo].[test-table]
  </code></pre>
  
  <p>Output is wrong (different). Can anyone tell me why? It's kinda this same.</p>