有这样两张表
表一: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=''我知道这个语句是错的,但是我需要实现这样的功能后来我想通过存储过程值传递来完成这样的功能:)当然如果不用存储过程就可以解决,也很好:)谢谢:)

解决方案 »

  1.   

    set fstoreunitid=
    (
    select fitemid from t_stock where fname=''
    )这句话好像是不行   一个列不能匹配一个记录集   如果记录集只有一条记录的时候可以
      

  2.   

    update t_icitembase 
    set fstoreunitid= t_stock.fitemid 
    from t_stock
    where t_icitembase.fstoreunitid=t_stock.fitemid and t_stock.fname=''
    你是不是这个意思。
      

  3.   

    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=''
      

  4.   

    update t_icitembase set fstoreunitid=b.fitemid
    from t_icitembase a ,t_stock b
    where a.fstoreunitid=b.fitemid and b.fname=''
      

  5.   

    好象大家误解我的意思了:)
    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这个属性的
      

  6.   

    CREATE PROCEDURE test  AS
    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用存储过程吧.哈哈