1

即使我已经尝试过其他帖子建议的仍然相同的错误,我也会收到此错误,但是当我运行 select 它工作正常...任何帮助将不胜感激

 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
4

1 回答 1

6

尝试在 UPDATE 中为表变量设置别名

例如

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
于 2012-06-30T13:57:01.637 回答