martedì 19 febbraio 2013

T-SQL, Row Value Concatenation Unsing "FOR XML PATH"

Sometime, could be usefull to concatenate row values.
For example you have a select that returns this result:


A
B
C
D


but you need:


A, B, C, D

the seguente script makes this: a Row Value Concatenation.


SELECT STUFF((
      SELECT
            ', ' + ltrim(rtrim(Your_Field))
      FROM
            Your_Table
      FOR XML PATH('')
),1,2,'')



My Two Cents ...

Nessun commento:

Posta un commento