Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your XQuery should be:</p> <pre><code>SELECT PersonID, Properties.value('(/PropertyList/Property[@Name="Class"])[1]','NVARCHAR(50)') FROM dbo.Person </code></pre> <p>Does that help??</p> <p><em>Update:</em> to make it clearer for others - I've added parenthesis around the <code>/PropertyList/Property[@Name="Class"]</code> expression, so that this will evaluate to potentially a list of values, and then the <code>[1]</code> after the parenthesis will select the first (and most often only) value (as a singleton) of that list so it can be converted to a <code>NVARCHAR(50)</code> string.</p> <pre><code>value('(/PropertyList/Property[@Name="Class"])[1]','NVARCHAR(50)') ! ! </code></pre> <p>is <strong>NOT</strong> the same as </p> <pre><code>value('/PropertyList/Property[@Name="Class"][1]','NVARCHAR(50)') </code></pre> <p><strong>Update 2:</strong> if you want to create a view - sure, no reason not to! ;-)</p> <p>You could definitely create something like:</p> <pre><code>CREATE VIEW dbo.YourViewName AS SELECT PersonID, PersonType, Title, ForeName, Surname, Company, Properties.value('(/PropertyList/Property[@Name="Class"])[1]','NVARCHAR(50)') AS 'Class', Properties.value('(/PropertyList/Property[@Name="CarRegistration"])[1]','NVARCHAR(50)') AS 'CarRegistration', Properties.value('(/PropertyList/Property[@Name="MedicalNotes"])[1]','NVARCHAR(50)') AS 'MedicalNotes' </code></pre> <p>from your table and "break up" the XML into columns on your view. Is that what you're looking for??</p>
    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