I'm facing some problem with a SQL query, I'm creating a variable :
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
The output from variable is :
'test','test2'
And here is a little part of my main 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]
which works correct but when I'm trying to do this like that :
SELECT
Number,
isnull(sum((case
when [Group] in (@material)
then isnull(cast([Quantity] as int), 0)
end)), 0) as other
FROM
[dbo].[test-table]
Output is wrong (different). Can anyone tell me why? It's kinda this same.