Home sql-server T-SQL: Combining the sample lines in one line

T-SQL: Combining the sample lines in one line

Author

Date

Category

There is select -creen, which returns 5 lines. How can you glue them into one with any separator?

Now I have it so: Select Comment + ',' from dbo.reason for xml path ('')

Maybe there is a better idea?

Thank you.


Answer 1, Authority 100%

declare @result nvarchar (MAX)
Select @Result = Coalesce (@Result + ',', '') + Comment
From dbo.reason.
SELECT @RESULT.

Answer 2

changed a little, at the end there will be a comma:

declare @result nvarchar (max) = ''
SELECT @RESULT = @RESULT + COMMENT + ','
From dbo.reason.
SELECT @RESULT

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions