Hvad med dette - dette vil fungere for et hvilket som helst antal <AAA>
noder i en XML-variabel:
DECLARE @Input XML = '<AAA>
<Name>Name_A</Name>
<Value>Val_A</Value>
</AAA>
<AAA>
<Name>Name_B</Name>
<Value>Val_B</Value>
</AAA>
<AAA>
<Name>Name_C</Name>
<Value>Val_C</Value>
</AAA>'
SELECT
STUFF(
(SELECT
',' + AAA.value('(Value)[1]', 'varchar(20)')
FROM
@Input.nodes('/AAA') AS Node(AAA)
FOR XML PATH('')
), 1, 1, '')
Output er:
Val_A,Val_B,Val_C