title: XQuery parent and child
body: <p>Example:</p>
  
  <pre><code>DECLARE @XML XML = '
  &lt;Items&gt;
      &lt;document id="doc1" value="100"&gt;
          &lt;details&gt;
              &lt;detail detailID="1" detailValue="20"/&gt;
              &lt;detail detailID="2" detailValue="80"/&gt;
          &lt;/details&gt;
      &lt;/document&gt;
      &lt;document id="doc2" value="0"&gt;
          &lt;details&gt;
          &lt;/details&gt;
      &lt;/document&gt;
  &lt;/Items&gt;
  '
  </code></pre>
  
  <p>I want results like this:</p>
  
  <pre><code>id    value    detailID   detailValue
  doc1  100      1          20
  doc1  100      2          80
  doc2  0        NULL       NULL
  </code></pre>
  
  <p>Tried:</p>
  
  <pre><code>SELECT document.value('../../@docID', 'VARCHAR(10)') AS 'docID',
         document.value('../../@value', 'INT') AS 'value',
         document.value('@detailID', 'VARCHAR(10)') AS 'detailID',
         document.value('@detailValue', 'INT') AS 'detailValue'
  FROM   @XML.nodes('Items/document/details/detail') AS Documents(document)
  </code></pre>
  
  <p>But, doc2 is not listed... Also, tried with CROSS JOIN and INNER JOIN, but performance is very bad.</p>