Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>declare @T table ( XMLCol xml ) insert into @T values ('&lt;AdultAsthma&gt; &lt;Group&gt; &lt;Question text="Act Score:" ForeColor="Green" /&gt; &lt;Controls&gt; &lt;Control type="Label" id="txtScore" text="Enter ACT Score:" ForeColor="Black"/&gt; &lt;Control type="TextBox" id="txtActScore" Answer="Answer" /&gt; &lt;/Controls&gt; &lt;/Group&gt; &lt;/AdultAsthma&gt; ') select XMLCol.value(N'(/AdultAsthma/Group/Question/@text)[1]', 'nvarchar(max)'), XMLCol.value(N'(/AdultAsthma/Group/Controls/Control/@Answer)[1]', 'nvarchar(max)') from @T </code></pre> <p>Update:</p> <p>When you need to shred your XML to multiple rows you can use <code>.nodes()</code> in a <code>cross apply</code>.</p> <pre><code>declare @T table ( XMLCol xml ) insert into @T values ('&lt;AdultAsthma&gt; &lt;Group&gt; &lt;Question text="Act Score:" ForeColor="Green" /&gt; &lt;Controls&gt; &lt;Control type="Label" id="txtScore" text="Enter ACT Score:" ForeColor="Black" /&gt; &lt;Control type="TextBox" id="txtActScore" Answer="" /&gt; &lt;/Controls&gt; &lt;/Group&gt; &lt;Group&gt; &lt;Question text="Do You Have Asthma?:" ForeColor="Black" /&gt; &lt;Controls&gt; &lt;Control type="RadioButton" id="rbHaveAsthmaYes" text="Yes" GroupName="Diagnosed" ForeColor="Black" Answer="False" /&gt; &lt;Control type="RadioButton" id="rbHaveAsthmaNo" text="No" GroupName="Diagnosed" ForeColor="Black" Answer="False" /&gt; &lt;/Controls&gt; &lt;/Group&gt; &lt;/AdultAsthma&gt; ') select X.N.value(N'(Question/@text)[1]', 'nvarchar(max)'), X.N.value(N'(Controls/Control/@Answer)[1]', 'nvarchar(max)') from @T as T cross apply T.XMLCol.nodes(N'/AdultAsthma/Group') as X(N) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload