title: Find if element exists in XML column of a SQL Server table
body: <p>I have data serialized to a XML column in a SQL Server table in the form:</p>
  
  <pre><code>&lt;Form title="Sample Data"&gt;
    &lt;MyProperty&gt;1234&lt;/MyProperty&gt;
    &lt;Employee&gt;
       &lt;MyProperty&gt;1234&lt;/MyProperty&gt;
    &lt;/Employee&gt;
  &lt;/Form&gt;
  </code></pre>
  
  <p>The element <code>MyProperty</code> can either be at the root level, or a child element under <code>&lt;Employee&gt;</code>. </p>
  
  <p>What I need is a SQL script that:</p>
  
  <ol>
  <li>Checks to see if <code>MyProperty</code> exists at the root level of the XML (I don't care about the child version of it)</li>
  <li>If it doesn't exist, insert the record at the root level.</li>
  </ol>
  
  <p>The value of <code>MyProperty</code> will have been previously calculated and I plan to place it into a temp table, along with the PK of the row that has the serialized XML.</p>
  
  <p>Can anyone give some guidance on how to do this?</p>