From: Plamen Ratchev on
Instead of using recursive CTE you can use FOR XML PATH to concatenate the rows:

SELECT DISTINCT A.[Key], C.data
FROM DataTable AS A
CROSS APPLY (SELECT '' + B.Data
FROM DataTable AS B
WHERE B.[Key] = A.[Key]
ORDER BY B.[No]
FOR XML PATH('')) AS C(data);

--
Plamen Ratchev
http://www.SQLStudio.com
From: Simon Woods on
Fantastic ... thx vm

On 20/04/2010 15:32, Plamen Ratchev wrote:
> Instead of using recursive CTE you can use FOR XML PATH to concatenate
> the rows:
>
> SELECT DISTINCT A.[Key], C.data
> FROM DataTable AS A
> CROSS APPLY (SELECT '' + B.Data
> FROM DataTable AS B
> WHERE B.[Key] = A.[Key]
> ORDER BY B.[No]
> FOR XML PATH('')) AS C(data);
>

From: --CELKO-- on
You do not do this in SQL or in RDBMS. We have this thing called First
Normal Form. We really like it since it is the foundation of the RM.

Use a report writer or application program to do display and front-end
work. You can also uses proprietary XML extensions, but that just
screams that you are not an SQL programmer at heart and want to lock
into Microsoft.