title: Deleting Multiple Nodes in Single XQuery for SQL Server
body: <p>I have:</p>
  
  <ol>
  <li>a table with an <strong>xml</strong> type column (list of IDs)</li>
  <li>an <strong>xml</strong> type parameter (also list of IDs)</li>
  </ol>
  
  <p>What is the best way to remove nodes from the column that match the nodes in the parameter, while leaving any unmatched nodes untouched?</p>
  
  <p>e.g.</p>
  
  <pre><code>declare @table table (
      [column] xml
  )
  
  insert @table ([column]) values ('&lt;r&gt;&lt;i&gt;1&lt;/i&gt;&lt;i&gt;2&lt;/i&gt;&lt;i&gt;3&lt;/i&gt;&lt;/r&gt;')
  
  declare @parameter xml
  set @parameter = '&lt;r&gt;&lt;i&gt;1&lt;/i&gt;&lt;i&gt;2&lt;/i&gt;&lt;/r&gt;'
  
  -- this is the problem
  update @table set [column].modify('delete (//i *where text() matches @parameter*)')
  </code></pre>
  
  <p>The MSDN documentation indicates it should be possible (in <a href="http://technet.microsoft.com/en-us/library/ms345122.aspx" rel="noreferrer">Introduction to XQuery in SQL Server 2005</a>):</p>
  
  <blockquote>
    <p>This stored procedure can easily be
    modified to accept an XML fragment
    which contains one or more skill
    elements thereby allowing the user to
    delete multiple skill nodes with a
    single invocation of stored procedure.</p>
  </blockquote>