Flatten column values ​​to row

Although I used the Sql server on a random basis for yonks, I did not understand until I came across it the other day so that you could do something like this:

declare @result varchar(8000) select @result = '' select @result = @result + acolumn+ ' ' from atable 

Nothing I read in the Transact-Sql docs made me think of using a construct like a cursor, for example. My question is: Is this design supported by other versions of Sql or is it Sql Server-specific?

+4
source share
2 answers

This is a specific Sql server. The above statements are T-SQL statements, and they are available only to Sql Server.

+3
source

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

+3
source

Source: https://habr.com/ru/post/1496001/


All Articles