| 发表于:2007-08-28 15:23:335楼 得分:0 |
这是我的存储过程 -- spu_in_out_qty_report '2007-01-29 ', '2007-09-29 ' create procedure spu_in_out_qty_report @start_date as varchar(20), @end_date as varchar(20) as declare @strsql as varchar(1000) declare @strtemptblin as varchar(300) declare @strtempout as varchar(300) declare @strtemptblinout as varchar(300) set @strsql= 'select * into ##temptbin from (select item_id,stock_spec_id, sum(po_stock_qty*ex_ratio) as in_qty from t_po_detail d inner join t_uom u on d.uom_id= u.uom_id where indate> = ' ' '+@start_date+ ' ' ' and indate <= ' ' '+@end_date+ ' ' ' group by item_id ,stock_spec_id ) a ' print @strsql EXEC(@strsql) if @@error> 0 begin goto error end set @strsql= 'select * into ##temptbout from (select item_id,stock_spec_id ,sum(so_stock_qty*ex_ratio) as out_qty from t_so_detail d inner join t_uom u on d.uom_id= u.uom_id where outdate> = ' ' '+@start_date+ ' ' ' and outdate <= ' ' '+@end_date+ ' ' ' group by item_id ,stock_spec_id ) b ' print @strsql EXEC(@strsql) if @@error> 0 begin goto error end set @strsql= 'select * into ##temptbinout from (select a.item_id,a.stock_spec_id, a.in_qty,a.out_qty from ( select isnull(ta.item_id,tb.item_id) as item_id,isnull(ta.stock_spec_id,tb.stock_spec_id) as stock_spec_id,ta.in_qty,tb.out_qty from ##temptbin ta full join ##temptbout tb on ta.item_id=tb.item_id and ta.stock_spec_id=tb.stock_spec_id) a)c ' print @strsql EXEC(@strsql) set @strsql= 'select m.part_no,m.full_name,s.stock_spec,isnull(in_qty,0) as in_qty,isnull(out_qty,0) as out_qty,t.item_id,t.stock_spec_id from ##temptbinout t inner join t_materiel m on t.item_id=m.item_id inner join t_stock_spec s on t.stock_spec_id=s.stock_spec_id ' print @strsql EXEC(@strsql) if @@error> 0 begin goto error end EXEC( 'drop table ##temptbin ') EXEC( 'drop table ##temptbout ') EXEC( 'drop table ##temptbinout ') goto error: go 请帮忙分析问题 | | |
|