Manoj Kumar (
manoj...@gmail.com) writes:
> I have a table as follows
>
> S. No. Month
> 1 Jan
> 1 Feb
> 1 Mar
> 2 Apr
> 3 Jun
> 2 Jul
> 3 Aug
>
> I want the result as follows:
>
> S. No. Month
> 1 Jan, Feb, Mar
> 2 Apr, Jul
> 3 Jun, Aug
>
> The s. No. should contain unique values after concatenation of month.
The standard solution is nothing you find by just reading the table
of contents in the T-SQL reference:
SELECT a.S, substring(b.list, 1, len(b.list) - 1)
FROM (SELECT DISTINCT S FROM tbl) AS a
CROSS APPLY (SELECT b.Month + ', '
FROM tbl b
WHERE a.S = b.S
ORDER BY b.Month
FOR XML PATH('')) AS b
--
Erland Sommarskog, Stockholm,
esq...@sommarskog.se