试图从 xml 中提取数据并更新 3 个表
ALTER PROCEDURE [dbo].[usp_UpdateOrderDetail]
@Request XML = '<Request/>'--,
--@Response XML = '<Response/>' OUTPUT
As
BEGIN
DECLARE @OrderID BIGINT
DECLARE @AddressID BIGINT
SET @OrderID = @Request.value('(Order/OrderID)[1]', 'BIGINT')
IF @OrderID > 0
BEGIN
-- this is where I am confused
UPDATE Orders O join Customers C on O.OrderID=C.OrderID SET
C.ContactName = T.C.value('ContactName[1]', 'varchar(50)'),
Phone = T.C.value('Phone[1]', 'varchar(50)'),
OrderDate = T.C.value('OrderDate[1]', 'varchar(50)')
FROM @Request.nodes('//Orders') as T(C)
WHERE OrderID = T.C.value('OrderID[1]', 'BIGINT')
END
ELSE
BEGIN
INSERT INTO Orders
(
ContactName
, Phone
, OrderDate
)
SELECT
T.C.value('ContactName[1]', 'varchar(50)')
, T.C.value('Phone[1]', 'varchar(50)')
, T.C.value('OrderDate[1]', 'varchar(50)')
FROM
@Request.nodes('//Order') AS T (C)
END
DECLARE @Counter INT
SET @Counter = 1
-- possibly more code here
END
第一条评论中的部分抛出一个错误,指出语法不正确......!
我将从所有 3 个表的几乎所有列中接收数据(为方便起见,此处不包括在内)。如何加入这 3 个表并更新每个表中的相应列?