Dynamic Pivot - Test

0

Please login or register to vote for this query.

(click on this box to dismiss)

Bonjour

Drupal Answers

Q&A for Drupal developers and administrators

DECLARE @XML as xml

SET @XML = '<Data Version="81">

  <NbGrossessesAnt>2</NbGrossessesAnt>
  <AntecedentsObs Id="1" Numdoc="">
    <Date>15/04/2000</Date>
    <Enfants Id="1">
      <Prenom>mathieu</Prenom>
    </Enfants>
  </AntecedentsObs>
  <AntecedentsObs Id="2" Numdoc="">
    <Date>30/09/2003</Date>
    <Remarque />
    <Enfants Id="2">
      <Prenom>alicia</Prenom>
    </Enfants>
  </AntecedentsObs>
  <AntecedentsGyneco Id="1" Date="20171218" Type="" Niveau="0">
    <Texte>frottis 2016</Texte>
  </AntecedentsGyneco>
</Data>'

SELECT 
    k.value('@ID','BIGINT') AS ID,
    b.value('local-name(.)','VARCHAR(50)') AS ColumnName,  -- get attribute name
    b.value('.','VARCHAR(MAX)') AS Value  -- get attribute value
FROM @XML.nodes('*/*') p(k)
CROSS APPLY k.nodes('@*') a(b)

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results