以下是我的查询:
Declare @ParentIDMap Table (AccTypeID BigInt, FullNo nvarchar(50), Branch BigInt, Code Varchar, ID BigInt)
Insert @ParentIDMap (AccTypeID, Branch, FullNo, Code)
Values (1, 5, '01111', 2),
-- Some other rows
(8, 5, '04121', 2)
Update @ParentIDMap
Set ID = Book.ID
From Accounting.ACNT.Book
Where Book.FullNo = @ParentIDMap.FullNo + @ParentIDMap.Code
错误:必须声明标量变量' @ ParentIDMap'
答案 0 :(得分:2)
您需要在@ParentIdMap
子句中引用FROM
才能更新(SqlServer以这种方式与其他RDBMS不同)。您也可以切换到联接:
Update p
Set p.ID = Book.ID
From Accounting.ACNT.Book
INNER JOIN @ParentIDMap p
ON Book.FullNo = p.FullNo + p.Code;