I'm trying to get this string_agg to put all the 'comments' into one result field like instead of:
433 2018-11-06 11:08:12.793 Customer called
433 2018-11-06 11:08:12.793 Customer left message
This is needed:
433 2018-11-06 11:08:12.793 Customer called, Customer left message
Any ideas?:
WITH MaxCommentCTE
AS (
SELECT DISTINCT client_id
,MAX(last_upd_dt) OVER (PARTITION BY client_id) AS LastCommentDate
,string_agg([comments], ', ') within
GROUP (
ORDER BY Comments
) AS Comment
FROM AB.dbo.tbl_reg_waiting
GROUP BY client_id
,last_upd_dt
,comments
)
SELECT *
FROM MaxCommentCTE