DECLARE @result varchar(MAX)
SELECT 
  NAME
FROM
  Table
WHERE
  ID = @Id
I need to fill @result with result Names, separated by ','.
For example, if SELECT returns 'A','B' and 'C', the @result should be 'A, B, C'.
It is Microsoft SQL Server 2008.
DECLARE @result varchar(MAX)
SET @result = '';
SELECT 
  @result = @result + NAME + ','
FROM
  Table
WHERE
  ID = @Id
SET @result = SUBSTRING(@result, 1, LEN(@result) - 1)
SELECT @result
Enjoy :D
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With