As in the the query if there is the table named #Table1 and have column FirstName.
Lets say there are 4 records in table having specified record in a script query.
If you want to those 4 rows value separated by any delimeter, in my example it is ' ; '
and assign into any variable, here variable is @listValues .
and do the following query:
SELECT @listValues = ISNULL(
@listValues + @delimeter + CAST(FirstName AS VARCHAR(8000)),
CAST(FirstName AS VARCHAR(8000))
)
FROM #Table1
ORDER BY FirstName
and then if you run the query
SELECT list = @listValues
you will get the result:
John ; Michiel ; Peter ; Smith