You're getting XML-encoded output. Change the query to:
SELECT
t1.HId,
commands = STUFF
(
(
SELECT DISTINCT ',' + t2.commands
FROM history_detail t2
WHERE t1.HId = t2.History_HID
FOR XML PATH(''), TYPE
).value('.', 'varchar(max)'), 1, 1, ''
)
FROM
history t1
;
- Add
,TYPE
after PATH('')
; - Add
.value('.', 'varchar(max)')
after the nested query;
There's no need to include
history_detail
in the outer query; removing it will also remove the need for the
GROUP BY
clause.
Concatenating Row Values in Transact-SQL - Simple Talk[
^]