+ -
当前位置:首页 → 问答吧 → 同时更新两张表的信息 sqlserver

同时更新两张表的信息 sqlserver

时间:2011-11-15

来源:互联网

update invHold set invHold.status ='1' 
where holdno='h20110008' and whseid='wh1' 
update inventory set 
inventory.status='HOLD'
 where invHold.lot=inventory.lot
 and invHold.loc=inventory.loc
 and invHold.lpn=inventory.lpn

但是报错
消息 4104,级别 16,状态 1,第 3 行
无法绑定由多个部分组成的标识符 "invHold.lot"。
消息 4104,级别 16,状态 1,第 3 行
无法绑定由多个部分组成的标识符 "invHold.loc"。
消息 4104,级别 16,状态 1,第 3 行
无法绑定由多个部分组成的标识符 "invHold.lpn"。

作者: damoyoushui   发布时间: 2011-11-15

没有这语法
update inventory set 
inventory.status='HOLD'
 where invHold.lot=inventory.lot
 and invHold.loc=inventory.loc
 and invHold.lpn=inventory.lpn

大概你是这个意思:
update inventory set 
inventory.status='HOLD'
from inventory,invHold
 where invHold.lot=inventory.lot
 and invHold.loc=inventory.loc
 and invHold.lpn=inventory.lpn

作者: perfectaction   发布时间: 2011-11-15

引用 1 楼 perfectaction 的回复:
没有这语法
update inventory set
inventory.status='HOLD'
where invHold.lot=inventory.lot
and invHold.loc=inventory.loc
and invHold.lpn=inventory.lpn

大概你是这个意思:
update inventory set
inventory.s……

作者: jwdream2008   发布时间: 2011-11-15

不能一句同时更新两个表.

update invHold set invHold.status ='1'  
where holdno='h20110008' and whseid='wh1' 
 
update inventory set  
status='HOLD'
from inventory , invHold
 where invHold.lot=inventory.lot
 and invHold.loc=inventory.loc
 and invHold.lpn=inventory.lpn

你可将两句话写在存储过程中,然后去调用存储过程.
create procedure my_proc
as
begin
update invHold set invHold.status ='1'  
where holdno='h20110008' and whseid='wh1' 
 
update inventory set  
status='HOLD'
from inventory , invHold
 where invHold.lot=inventory.lot
 and invHold.loc=inventory.loc
 and invHold.lpn=inventory.lpn
end

作者: dawugui   发布时间: 2011-11-15

不能同时更新两张表,要分开写.如果要保证一次完成,可以加一个显式事务.
begin tran
update...
update...
commit

作者: qianjin036a   发布时间: 2011-11-15

update invHold 
set invHold.status ='1' 
FROM inventory
where holdno='h20110008' and whseid='wh1' 


update inventory 
set 
inventory.status='HOLD'
FROM invHold
 where invHold.lot=inventory.lot
 and invHold.loc=inventory.loc
 and invHold.lpn=inventory.lpn

--少了from

作者: roy_88   发布时间: 2011-11-15

SQL code
update
 a
set  
 inventory.status='HOLD'
from
 inventory a ,invHold b
where
 a.lot=b.lot
 and a.loc=b.loc
 and a.lpn=b.lpn

作者: fredrickhu   发布时间: 2011-11-15