1

I'm updating a table through XML file but when I execute the sql code it throw this error :-

enter image description here

And here is my code

IF(@PreppedUpdateModelXml is NULL OR @PreppedUpdateModelXml.exist('*') = 0)
            BEGIN
                --Create an internal representation of the XML document.
                EXEC sp_xml_preparedocument @PID OUTPUT,@PreppedUpdateModelXml

                UPDATE EquipmentModel
                SET [Category] = em.[Category]
                SELECT * FROM OPENXML (@PID, '/Root/NewDataSet',2)
                WITH ([Category] VARCHAR(50), [ModelID] INT) AS em
                WHERE EquipmentModel.ModelID = em.ModelID
            END
petelids
  • 12,305
  • 3
  • 47
  • 57
Abhay
  • 47
  • 1
  • 10

1 Answers1

1

Thats not the right syntax to update table with Openxml result, try this way

UPDATE e
SET    [Category] = em.[Category]
FROM   EquipmentModel e
       JOIN OPENXML (@PID, '/Root/NewDataSet', 2)
               WITH ([Category] VARCHAR(50),
                     [ModelID]  INT) em
         ON e.ModelID = em.ModelID 
Pரதீப்
  • 91,748
  • 19
  • 131
  • 172