title: Passing xml string parameter to SQL Server stored procedure
body: <p>I am passing an xml string to stored procedure in SQL Server for inserting 10000 records to my table. In this when I call this stored procedure. Want to check the SQL Server table with that xml string which I am passing, if the record exists I don't want to insert, if it is new record that record alone have to insert.Give some solution. Thanks. </p>
  
  <pre><code>  ALTER procedure [dbo].[SP_CMSUSER1]
        (@xmlString ntext)
      as
      begin
  
        DECLARE @idoc INT
        DECLARE @data nvarchar(100)
  
        EXEC sp_xml_preparedocument @idoc OUTPUT, @xmlString
  
      INSERT INTO dbo.Seg_RecipientsTemp (ContactID,first_name,last_name,company,email,last_updated)
      SELECT ContactID,
      first_name,
      last_name,
      company,
      email,
      last_updated FROM OPENXML(@idoc,
  
      '/NewDataSet/ContactData', 6)
  
      WITH
  
      (ContactID int ,
      first_name nvarchar(50), 
      last_name  nvarchar(50), 
      company    nvarchar(max),
      email nvarchar(100), 
      last_updated datetime 
  
  
  
      )
      end
  </code></pre>
  
  <p>My Xml is:</p>
  
  <pre><code> &lt;NewDataSet&gt;
    &lt;Table&gt;
      &lt;ContactID&gt;2&lt;/ContactID&gt;
      &lt;last_name&gt;klklk&lt;/last_name&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;ContactID&gt;4&lt;/ContactID&gt;
      &lt;first_name&gt;k&lt;/first_name&gt;
      &lt;last_name&gt;kk&lt;/last_name&gt;
      &lt;company&gt;k&lt;/company&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;ContactID&gt;6&lt;/ContactID&gt;
      &lt;first_name&gt;naveen&lt;/first_name&gt;
      &lt;last_name /&gt;
      &lt;company&gt;inno&lt;/company&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;ContactID&gt;7&lt;/ContactID&gt;
      &lt;first_name&gt;sridar&lt;/first_name&gt;
      &lt;last_name /&gt;
      &lt;company&gt;mahindara&lt;/company&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;ContactID&gt;1&lt;/ContactID&gt;
      &lt;first_name&gt;terst&lt;/first_name&gt;
    &lt;/Table&gt;
    &lt;Table&gt;
      &lt;ContactID&gt;2&lt;/ContactID&gt;
      &lt;first_name /&gt;
      &lt;last_name&gt;ask&lt;/last_name&gt;
      &lt;company /&gt;
    &lt;/Table&gt;
  &lt;/NewDataSet&gt;
  </code></pre>