select ProductId from Products I am getting the output as follows: ProductId
1
2
3
4
I want to get output as like follow:
ProductID
1,2,3,4
select ProductId from Products I am getting the output as follows: ProductId
1
2
3
4
I want to get output as like follow:
ProductID
1,2,3,4
Try This:
declare @aa varchar (200)
set @aa = ''
select @aa =
case when @aa = ''
then cast(Productid as varchar)
else @aa + coalesce(',' + cast(Productid as varchar), '')
end
from Products
print @aa