Friday, August 28, 2009

using COALEASE in t-sql

So, you have text you want to select for all the rows of a table, almost similar to AVG function for numbers

Here is the solution I found, thanks Viper

DECLARE @AllNotes varchar(4000)

SELECT @AllNotes = COALESCE(@AllNotes + ', ', '') + (Notes + ' (added by ' + addedby + ')')
FROM   Ranking
WHERE  scholarshipID=52

PRINT @AllNotes