Monday, October 17, 2011

Sample of COALESCE in SQL SERVER


DECLARE @List nvarchar(100)
select @List= COALESCE(@List + ',', '') + colValue  from TableFields where categoryId = 15 and LOWER(name) <> 'subject'
select @List

This will return a concatenated string with all the values (in all rows) for the column colValue and categoryId = 15. (the categoryId could be a parameter  @categoryId)

No comments:

Post a Comment