我尝试执行更新语句时遇到问题在SQL Server 2012中:
update ScmInOutD
set QtyValue= (select case when ScmInOutMas.InOutType ='I' or ScmInOutMas.InOutType ='B' then Qty else Qty*-1 end Qty
from
ScmInOutMas,ScmInOutD where ScmInOutD.InOutID = ScmInOutMas.InOutID)
错误消息显示给我:
子查询返回的值超过1。当子查询遵循=,!=,<,< =,>,> =或子查询用作表达式时,不允许这样做。
答案 0 :(得分:1)
尝试在JOIN
声明中使用UPDATE
update SD
set SD.QtyValue= (case when SM.InOutType ='I' or SM.InOutType ='B' then Qty else Qty*-1 end)
FROM ScmInOutD SD
JOIN ScmInOutMas SM ON SD.InOutID = SM.InOutID