MartynA
MartynA

Reputation: 30715

Flatten column values into a string

Although I've been using Sql Server on an occasional basis for yonks, I didn't realise until I stumbled across it the other day that you could do something like this:

declare @result varchar(8000)

select @result = ''

select @result = @result + acolumn+ ' '

from atable

Nothing I'd read in the Transact-Sql docs led me to think of using a construct like that rather than e.g. a cursor. My question: Is this construct supported by other versions of Sql or is it Sql Server-specific?

Upvotes: 4

Views: 725

Answers (2)

Michael Goldshteyn
Michael Goldshteyn

Reputation: 74380

Do not do this, because it depends on the physical implementation and internal access paths. Please read the article on Concatenating Row Values in Transact-SQL for several correct approaches such as the FOR XML PATH('') approach.

Upvotes: 3

nhrobin
nhrobin

Reputation: 903

This is Sql server specific. The statements you mentioned are T-SQL statements and they are only available for Sql Server.

Upvotes: 3

Related Questions