把#HHH 临时表中的很多记录批量在存储过程中插入到#GGG表中sql怎么写啊???(注:#GGG中原来有数据,还要把临时表中的记录再往里插)
begin
select  fgoods_id, sum(fnum)as currentNum,sum(fnum*inprice)as currentMoney into #HHH from t_stock_detail group by fgoods_idinsert into #GGG values(t2.fgoods_id,0,0,0,0,t2.currentnum,t2.currentmoney) from #HHH t2 where  fgoods_id not in (select fgoods_id from t2)
end

解决方案 »

  1.   

    insert into #GGG values(t2.fgoods_id,0,0,0,0,t2.currentnum,t2.currentmoney) from #HHH t2 where  fgoods_id not in (select fgoods_id from t2) 
    是有问题的 #GGG 表有7个字段 ,#HHH表有3个字段 就把三个字段插入到 #GGG表的1 6 7字段中就可以了其余都插0
      

  2.   

    insert into #GGG values(t2.fgoods_id,a,b,c,d,t2.currentnum,t2.currentmoney) 
    select fgoods_id,'0','0','0','0',currentnum,currentmoney from #HHH t2 where  fgoods_id not in (select fgoods_id from t2) 
      

  3.   

    insert into #GGG 
    select * from #HHH t2 where  fgoods_id not in (select fgoods_id from t2) 
      

  4.   

    3楼大哥还是报错误啊!!!上下文中不允许fgoods_id
      

  5.   

    搂主的语法没有问题吧?
    像3楼那么写的话,应该是可以的。
    其中select * from #HHH t2 where  fgoods_id not in (select fgoods_id from t2) 
    改为select t2.fgoods_id,0,0,0,0,t2.currentnum,t2.currentmoney from #HHH t2 where  fgoods_id not in (select fgoods_id from t2) 试试