سؤال

I have the following xml

declare @xml xml = '<Values><a>AAA</a><b>BBB</b></Values>';
select @xml.query('for $k in /Values return concat(",@", "=''", $k, "''")')

It returns

,@='AAABBB'

However I expect

,@a='AAA',@b='BBB'

How to write the xquery?

هل كانت مفيدة؟

المحلول

I figured it out myself.

declare @xml xml = '<Values><a>AAA</a><b>BBB</b></Values>';
select @xml.query('for $k in /Values/* 
    return concat(",@", fn:local-name($k), "=''", $k, "''")')
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top