Function GROUP_CONCAT เป็น Function ของ MySql ใน SQL Server ไม่มีนะครับ

เป้าหมายคือจากตารางนี้

ให้ได้ผลตามนี้

Download ตัวอย่างได้ตาม Link นี้เลยครับ GroupConcatExample

SELECT  [FAQ ID],
        SUBSTRING(d.[Category Name], 0, LEN(d.[Category Name])) [Category Name]
FROM    V_FaqCategory a CROSS apply
        (SELECT [Category Name] + ', '
         FROM   V_FaqCategory b
         WHERE  a.[FAQ ID] = b.[FAQ ID] FOR XML PATH('')) D([Category Name])
GROUP BY [FAQ ID], d.[Category Name]
SELECT	T1.[FAQ	ID], T1.[Topic],
		(
			SELECT	CONVERT(VARCHAR,T2.[Category ID]) +	','
			FROM	TBL_FaqCat T2
			WHERE	T2.[FAQ	ID]	= T1.[FAQ ID]
			FOR	XML	PATH('')
		) AS Category
FROM	TBL_Faq	T1
SELECT	T1.[FAQ	ID], T1.[Topic],
		SUBSTRING((
			SELECT	CONVERT(VARCHAR,T2.[Category ID]) +	','
			FROM	TBL_FaqCat T2
			WHERE	T2.[FAQ	ID]	= T1.[FAQ ID]
			FOR	XML	PATH('')
		),0,LEN((
			SELECT	CONVERT(VARCHAR,T2.[Category ID]) +	','
			FROM	TBL_FaqCat T2
			WHERE	T2.[FAQ	ID]	= T1.[FAQ ID]
			FOR	XML	PATH('')
		)))	AS Category
FROM	TBL_Faq	T1

ที่มา: http://stackoverflow.com/questions/451415/simulating-groupconcat-mysql-function-in-ms-sql-server-2005
http://anthony-yio.blogspot.com/2007/12/mssql-groupconcat.html
http://greatfriends.biz?118776
http://blog.shlomoid.com/2008/11/emulating-mysqls-groupconcat-function.html