sql - What is the best way to collapse the rows of a SELECT into a string? -


In a SQL statement (or process) I want to narrow the rows of this table into a single comma-delimited string.

  Normal id value - ----- 1 "a" 2 "b" 3 "c"  

for:

  "A, B, C"  

You can get an embedded You can insert a query in the 'Set' statement:

 Announced @ Combined varchar (2000) @combined = isnull (@combined + ',', '') + isnull Value, '') Simple Stable Print @ Combined 

(Note that the first isnull () starts the string, and the second isnull () is particularly important if tap into the 'value' column Any chance, because otherwise there could just tap the insertion)

(edit code and explanations after the comment)


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -