Click here to Skip to main content
16,020,294 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a problem when I try to concatenate few rows. The program just keep adding the same data the number of times that it exist. For example if I want to concatenate 6 rows into 1, and each rows contain something like this:
XML
Alabama : Huntsville
California : Los Angeles
Miami : Florida
Michigan : Detroit
Ohio : Cleveland
Texas : Houston

(This is not the real data is just an example)
It is doing the following:
Row State:Capital
1 Alabama : Huntsville, California : Los Angeles, Miami : Florida,
Michigan : Detroitm, Ohio : Cleveland, Texas : Houston, Alabama :
Huntsville, California : Los Angeles, and so on...

I am using CROSS APPLY, an using as example this:
SQL
SELECT DISTINCT CategoryId, ProductNames
FROM Northwind.dbo.Products p1
CROSS APPLY ( SELECT ProductName + ',';
FROM Northwind.dbo.Products p2
WHERE p2.CategoryId = p1.CategoryId
ORDER BY ProductName
FOR XML PATH('') ) D ( ProductNames )
Posted
Updated 22-Sep-10 6:45am
v2

1 solution

 
Share this answer
 
Comments
jalmonte 22-Sep-10 13:22pm    
Reason for my vote of 5
Automatic vote of 5 for accepting answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900