Saturday, August 22, 2009

Concatenation in Sql Query

select * from DataTypeCategory
--if i run this query i will get result like that.

--now i want to concatenate all the same category data type so i have to write query like that

SELECT A.Category,
(SELECT B.DataType + ',' FROM DataTypeCategory B WHERE B.Category=A.Category
FOR XML PATH('')) 'Concatinated' FROM DataTypeCategory A GROUP BY A.Category

No comments:

Post a Comment