I want to select a dataset in one row, but I still want each element in its row (I will then put it in Crystal Reports, and it will be faster than using a ton of subscriptions).
So, I have the following data:
ID Assessor 1 Black 1 Jones
and I want to query it and return a single line that looks like this:
Black Jones
if I make a choice using coalesce, I can make it a comma or a comma separator, but not limit the line:
BEGIN declare @Assessors NVarChar(max) Declare @LineFeed varchar(10) DECLARE @Return varchar(10) Set @LineFeed = char(10) SET @Return = char(13) Select @Assessors = COALESCE(@Assessors + ', ', '') + a.Assessor FROM dbo.Assessment a Where (@ID = a.ID) Return @Assessors END
then the function will return "Black, Jones." But if I changed the line to
Select @Assessors = COALESCE(@Assessors + @Return + @LineFeed, '') + a.Assessor
it returns Black Jones - it does not put a string or returns, just a space.
I think I do not need to use Coalesce, but I tried only standard concatenation, and that also does not fit. I have this in a function right now, but I plan to put it as part of a stored procedure, so it's faster.
sql-server string-concatenation newline sql-server-2008
thursdaysgeek
source share