1

我正在通过 XML 文件更新表,但是当我执行 sql 代码时,它会抛出此错误:-

在此处输入图像描述

这是我的代码

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
4

1 回答 1

1

那不是用结果更新表的正确语法Openxml,试试这种方式

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 
于 2017-07-10T11:53:18.470 回答