I have a question. I know that has been asked before. I looked through the related questions but I could not get my SQL script to work.
Here is my query :
SELECT T1.PART_ID, T2.ID, T2.DESCRIPTION
FROM #TEMP T1
INNER JOIN #TEMP2 T2 ON T1.PART_ID = T2.PART_ID
ORDER BY T2.ID
Table:
PART_ID | ID | DESCRIPTION
----------------------------------
10002 | 1182505 | Tagfahrlichtschaltung
80029 | 1182505 | Bluetooth
20004 | 1212866 | Kindersitzbefestigung
10045 | 1212866 | Lederlenkradrriegelung
11908 | 1257946 | Airbag
22346 | 1257946 | Automatic
I want have the result like:
ID | LISTOFPARTS
-----------------------------
1182505 | "10002 : Tagfahrlichtschaltung ; 80029 : Bluetooth "
1212866 | "20004 : Kindersitzbefestigung ; 10045 : Lederlenkradrriegelung"
1257946 | "11908 : AIRBAG ; 22346 : AUTOMATIC"
I guess it has to be something with XML PATH but I could not get it to work. Could anyone rewrite the query so that it returns the results grouped and concatenated in string?
Solutions with or without XML PATH will be appreciated.
Thanks!
http://sqlfiddle.com/#!3/d41d8/5441
This will work -