Concatenation string

Is there a way in the SQL segment that can write the output as follows:

select events
  from mytable

source conclusion

events
--------
123456
894531
985233
829292
920202
392939
299223

desired output

'123456', '894531','985233','829292','920202','392939','299223'

select '' + CustomerID + ',' from dbo.Customers Custom ID ALFKI, ANATR, ANTON, AROUT, BERGS,

I would like to see the result as User ID 'ALFKI', 'ANATR', "ANTON", 'AROUT', 'BERGS', and so on ...

+3
source share
2 answers
SELECT
  STUFF(
    (SELECT
      ', ' + events
     FROM dbo.mytable
     FOR XML PATH('')
    ), 1, 1, '') As concatenated_string

If you want the values ​​to be enclosed in single quotes, then edit the pending label.

+5
source

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


All Articles