把#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
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
是有问题的 #GGG 表有7个字段 ,#HHH表有3个字段 就把三个字段插入到 #GGG表的1 6 7字段中就可以了其余都插0
select fgoods_id,'0','0','0','0',currentnum,currentmoney from #HHH t2 where fgoods_id not in (select fgoods_id from t2)
select * from #HHH t2 where fgoods_id not in (select fgoods_id from t2)
像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) 试试