I have a table with a column:
|-------------|
| ColumnName |
|-------------|
| Value One |
| Value Two |
| Value Three |
| Value Four |
| Value Five |
|-------------|
I will declare a variable,
DECLARE @ColumnNameList VARCHAR(MAX)
and I should find the below value in my variable
'Value One,Value Two,Value Three,Value Four,Value Five'
Can anyone help me out in doing this?
Thanks in advance.
SELECT @ColumnNameList = STUFF
(
SELECT ',' + ColumnName
FROM TableName
ORDER BY ColumnName
FOR XML PATH('root')
), 1, 1, ''
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With