我收到此错误,即使我已经尝试了其他帖子建议仍然相同的错误 但当我运行选择它工作正常... 任何帮助将不胜感激
ALTER PROCEDURE UpdateCustomers
@XML AS XML
AS
DECLARE @tempTbl TABLE(
tblID INT ,
Customer_name NVARCHAR(30),
Customer_Code NVARCHAR(10)
)
INSERT INTO @tempTbl(tblID, Customer_name, Customer_Code)
SELECT
Item.element.value('@tblID', 'int'),
Item.element.value('@Customer_name', 'nvarchar(30)'),
Item.element.value('@Customer_Code', 'nvarchar(10)')
FROM
@xml.nodes('/root/item') AS Item(element)
--SELECT * FROM @tempTbl---it runs ok
UPDATE dbo.Customers
SET
dbo.Customers.Customer_name = @tempTbl.Customer_name,
dbo.Customers.Customer_Code = @tempTbl.Customer_Code
from dbo.Customers
inner join @tempTbl
on Customers.tblID =@tempTbl.tblID
答案 0 :(得分:6)
尝试在UPDATE中对表变量进行别名
e.g。
UPDATE dbo.Customers
SET
dbo.Customers.Customer_name = tmp.Customer_name,
dbo.Customers.Customer_Code = tmp.Customer_Code
from dbo.Customers
inner join @tempTbl tmp
on Customers.tblID = tmp.tblID