title: SQL UPDATE table with OPENXML
body: <p>I want to UPDATE a table within the following OPENXML statement but don't know where to put the syntaxes as UPDATE, FROM and WHERE.</p>
  
  <p>I get a nice resultset with the OPENXML statement but how do I UPDATE a table with it?</p>
  
  <pre><code>DECLARE @x xml
  
  SELECT @x=R
  FROM OPENROWSET (BULK 'C:\Users\ronal\Dropbox\Projecten\Voormelden Portbase\20161021095457591.xml', SINGLE_BLOB) AS XMLPortbase(R)
  
  DECLARE @hdoc int
  EXEC sp_xml_preparedocument @hdoc OUTPUT, @x
  
  
      UPDATE [COMTECdefault].[dbo].[voormelden] 
  SET 
      Tarcode = '12345678'
  
  FROM OPENXML (@hdoc, '/StandardBusinessDocument/documentContent/contentBody/Acknowledgement/messageStatus',3)
  WITH (
          previousContentReference varchar(50) '../../../previousContentHeader/contentReference',
          messageAcceptanceCode varchar(50) '../messageAcceptanceCode',
          timeslotReference varchar(50) '../timeslotReference',
          offeredArrivalDateTime DateTime '../offeredArrivalDateTime',
          offeredDepartureDateTime DateTime '../offeredDepartureDateTime',
          messageStatusCode varchar(255),
          messageStatusDescription varchar(255),
          additionalStatusRemarks varchar(255),
          containerPrefixAndNumber varchar(50) '../containerPrefixAndNumber'
      )
  WHERE ID = previousContentReference
  
  EXEC sp_xml_removedocument @hdoc
  </code></pre>