Pergunta

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?

Foi útil?

Solução

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, "''")')
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top