I am trying to convert XML node values to comma separated values but, getting a
Incorrect syntax near the keyword 'SELECT'. error message
declare @dataCodes XML = '<Root>
<List Value="120" />
<List Value="110" />
</Root>';
DECLARE @ConcatString VARCHAR(MAX)
SELECT @ConcatString = COALESCE(@ConcatString + ', ', '') + Code FROM (SELECT T.Item.value('@Value[1]','VARCHAR(MAX)') as Code FROM @dataCodes.nodes('/Root/List') AS T(Item))
SELECT @ConcatString AS Result
GO
I tried to follow an article but not sure how to proceed further. Any suggestion is appreciated.
Expectation:
Comma separated values ('120,110') stored in a variable.