If you want to concatenate string values from multiple rows in SQL, use one of the methods described in this artice:
Concatenating Row Values in Transact-SQL[
^]
For example:
SELECT
p1.CategoryId,
STUFF(
(
SELECT ',' + ProductName
FROM Northwind.dbo.Products p2
WHERE p2.CategoryId = p1.CategoryId
ORDER BY ProductName
FOR XML PATH(''), TYPE
).value('.', 'varchar(max)')
, 1, 1, '')
As Products
FROM
Northwind.dbo.Products p1
GROUP BY
CategoryId
;
If that's
not what you want to do, then you'll need to update your question to explain the problem more clearly. If possible, create a
SQL Fiddle[
^] with some sample data to demonstrate the problem.