I have two table, which are joined together and stored in a temp table.
The Temp table consist the data in following form:
|ID|Name |Code|
|1 | 100 |AAAA|
|1 | 100 |AAAB|
|1 | 100 |AAAA|
|2 | 200 |AAAZ|
more...
Now I want the outcome in the following form,
╔════╦═════════════════════╗
║ ID ║ Name ║ Code ║
╠════╬═════════════════════╣
║ 1 ║ 100 ║ AAAA, AAAB ║
║ 2 ║ 200 ║ AAAZ ║
╚════╩═════════════════════╝
So I have written the Following Query, which produces the similar output, So my question is that, Is there any other way to achieve this.
SELECT Distinct BSE_ID
,BSE_Name
,STUFF((
SELECT ', ' + CAST(EBS_ExternalCode AS VARCHAR(100)) [text()]
FROM #tmpBkgSvc
WHERE BSE_ID = T.BSE_ID
FOR XML PATH('')
,TYPE
).value('.', 'NVARCHAR(MAX)'), 1, 2, ' ') EBS_ExternalCode
FROM #tmpBkgSvc T