0
Declare @modCode varchar(3)
SET @modCOde = 'SOR';

UPDATE  Doc_SalesOrder
SET     OLD_SP.Num = NEW_SP.NewNum
FROM    Doc_SalesOrder as OLD_SP
INNER JOIN
(
     Select
       Id,
       dbo.ApplyModuleCode(@modCode,Num) as NewNum 
     From Doc_SalesOrder
     Where Num not LIKE '%'+@modCOde+'%'
)NEW_SP ON OLD_SP.Id = NEW_SP.Id

当我运行查询时,错误是:

无法绑定多部分标识符“OLD_SP.Num”。

为什么?

4

1 回答 1

4

利用

UPDATE  OLD_SP
SET     OLD_SP.Num = NEW_SP.NewNum
FROM    Doc_SalesOrder as OLD_SP /* .... */

或者只是简单地将表前缀完全放在 set 语句目标中。这里没有歧义。

UPDATE  Doc_SalesOrder
SET     Num = NEW_SP.NewNum
FROM    Doc_SalesOrder as OLD_SP /* .... */
于 2012-11-07T07:57:44.273 回答