stoperror
Goto Top

MSSQL xquery - Attribute eines XML-Tags in eigene Tags umwandeln

Ich möchte gerne aus einem XML-Feld aus der DB von einem Tag alle Attribute in eigenständige Tags umwandeln.

Das folgende ist noch nicht ganz das, was ich möchte. Die Richtung dürfte aber schon stimmen...

select
logdate,
XMLContent,

XMLContent.query(
'for $Entry in descendant-or-self::MyTag
return
element MyTag
{
for $Attribute in $Entry/@*
return

<Attribut>{$Attribute}</Attribut>


}
')


from logtable

Output;

<MyTag>
<Attribut Nummer="123" />
<Attribut System="0" />
</MyTag>

Ich möchte aber:
<MyTag>
<Nummer>123</Nummer>
<System>0</System>
</myTag>

Anschliessend möchte ich jedes MyTag in eine extra Spalte und alle Attribute in eine extra Spalte bekommen via Tabellenvariablen.

Hat jemand eine Idee, wie man das geschickt hinbekommt?

Das Script soll so sein, dass es mit jedem beliebigen Tag und jedem beliebigen Attribut (also dynamisch) funktioniert.

Danke schon mal für Eure Hilfe.

Content-Key: 155952

Url: https://administrator.de/contentid/155952

Printed on: April 24, 2024 at 23:04 o'clock