I’m stuck on an aggregation problem that I can’t get to the bottom of.
I have some data which is best summarized as follows
id |phraseId|seqNum|word
=========================
1 |1 |1 |hello
2 |1 |2 |world
3 |2 |1 |black
4 |2 |2 |and
5 |2 |3 |white
I’d like a query that gives back the following data:
phraseId|completePhrase
========================
1 |hello world
2 |black and white
Anyone?
EDIT
I notice all the provided solutions use FOR XML PATH. What is this magic?
One solution is to create an UDF using an FOR XML PATH expression.
SQL Statement
Creating the UDF
edit
After revising some of the links myself, an even shorter solution is
SQL Statement