Пример запроса:
DECLARE @idName INT
SET @someColumn = 7
DECLARE @s VARCHAR(MAX)
SET @s = ''
SELECT @s = @s + CASE WHEN @s <> '' THEN ', ' ELSE '' END + CAST(myColumn AS VARCHAR)
FROM t1
WHERE someColumn = @someColumn
SELECT @s AS ResultList
Пример запроса:
DECLARE @idName INT
SET @someColumn = 7
DECLARE @s VARCHAR(MAX)
SET @s = ''
SELECT @s = @s + CASE WHEN @s <> '' THEN ', ' ELSE '' END + CAST(myColumn AS VARCHAR)
FROM t1
WHERE someColumn = @someColumn
SELECT @s AS ResultList