Below is my code.
DECLARE @msg NVARCHAR(MAX) = NULL
;WITH CTE AS (
SELECT 'A' AS Message
UNION
SELECT 'B' AS Message
UNION
SELECT 'C' AS Message
UNION
SELECT 'D' AS Message
)
SELECT @msg = COALESCE(ISNULL(@msg,'Attachements') + ', ','') + Message FROM CTE
SELECT @msg + ' are missing.'
It is generating output :-
Attachments, A, B, C, D are missing.
How can I avoid first comma after word "Attachments
" ? Please help.
Other techniques to satisfy the requirement would also be welcome.
Thanks.