有这样两张表
表一:t_icitembase里面有一个字段fstoreunitid(外键)
表二:t-stock里面有两个字段finterid(主键)和fname由于fstoreunitid是外键,关联的是finterid我想实现以下的功能:update t_icitembase set fstoreunitid=
(
select fitemid from t_stock where fname=''
)
where t_icitembase.fstoreunitid=t_stock.fitemid and fname=''我知道这个语句是错的,但是我需要实现这样的功能后来我想通过存储过程值传递来完成这样的功能:)当然如果不用存储过程就可以解决,也很好:)谢谢:)
表一:t_icitembase里面有一个字段fstoreunitid(外键)
表二:t-stock里面有两个字段finterid(主键)和fname由于fstoreunitid是外键,关联的是finterid我想实现以下的功能:update t_icitembase set fstoreunitid=
(
select fitemid from t_stock where fname=''
)
where t_icitembase.fstoreunitid=t_stock.fitemid and fname=''我知道这个语句是错的,但是我需要实现这样的功能后来我想通过存储过程值传递来完成这样的功能:)当然如果不用存储过程就可以解决,也很好:)谢谢:)
(
select fitemid from t_stock where fname=''
)这句话好像是不行 一个列不能匹配一个记录集 如果记录集只有一条记录的时候可以
set fstoreunitid= t_stock.fitemid
from t_stock
where t_icitembase.fstoreunitid=t_stock.fitemid and t_stock.fname=''
你是不是这个意思。
set t_icitembase.fstoreunitid=t_stock.fitemid
from t_icitembase inner join t_stock
on t_icitembase.fstoreunitid=t_stock.fitemid
where t_icitembase.fname=''
and t_stock.fname=''
from t_icitembase a ,t_stock b
where a.fstoreunitid=b.fitemid and b.fname=''
yangzyu(z.yu)update t_icitembase
set t_icitembase.fstoreunitid=t_stock.fitemid
from t_icitembase inner join t_stock
on t_icitembase.fstoreunitid=t_stock.fitemid
where t_icitembase.fname=''
and t_stock.fname=''
的很接近我的意思,但是t-stock里面没有fname这个属性的
declare @finterid int(4)
declare cur cursor for select fitemid from t_stock where fname=''
open cur
fetch cur into @finterid
while (@@fetch_status=0)
begin update t_icitembase set fstoreunitid=@finterid where t_icitembase.fstoreunitid=t_stock.fitemid and fname='' fetch cur into @finterid
end
close cur
deallocate curGO用存储过程吧.哈哈