物资统计 (解决可以多加分) (50分)

H

hqlww

Unregistered / Unconfirmed
GUEST, unregistred user!
管理需要,将仓库的月入库,月出库数量及金额帐在表中反映出来,现在我需要从入库表,出库
表中统计出数据,放在一个叫结存表中,用来查询每个月的出入库情况,怎么从这两个表中得
到数据,将所得到的数据放在结存表中?
(在入库表中按物资代码进行统计出各种物资的入库数量,显示出来)
 
你的问题太泛泛了,说清楚点儿,我现在就正在做这样一个东东,可以和我联系。realtime@yeah.net
 
仓库管理中有的啊,物资字典建立的时候有当前库存,上月库存及变化情况
现在要尽心统计分析啊,你想,要给出库表,入库表关联起来,从而得到需要的数据,进行
分析,是不是这样!
 
能否將你的入库表,出庫表,结存表的表結構貼出來?
 
卡住起始日期和结束日期(一般会计月份是指上个月26号至本月25号)),根据时间段进行筛选,
然后统计出入出库金额
 
可參考(以下代碼自己寫個存儲過程):
if exists (select name from sysobjects where name='st_in') drop table st_in
create table St_in /*進貨表*/
(
inv_no varchar(30),/*產品編號*/
op_date datetime,/*進貨日期*/
quan float,/*數量*/
primary key(inv_no,op_date)
)
if exists (select name from sysobjects where name='st_out') drop table st_out
create table St_out
(
inv_no varchar(30),/*產品編號*/
op_date datetime,/*出貨日期*/
quan float,/*數量*/
primary key(inv_no,op_date)
)
if exists (select name from sysobjects where name='st_end') drop table st_end
create table st_end /*結存表*/
(
inv_no varchar(30), /*產品編號*/
quan_in float, /*本用進貨數量*/
quan_out float, /*本用出貨數量*/
primary key(inv_no)
)
declare @date1 varchar(7)
/*格式2001-04*/
select @date1='2001-01' /*你可輸入查詢的月份,應加上年份*/
delete from st_end
insert st_end (inv_no,quan_in,quan_out) select inv_no,sum(quan),0 from st_in
where left(convert(varchar(10),op_date,20),7)=@date1 group by inv_no
update st_end set quan_out=(select isnull(sum(quan),0) from st_out
where left(convert(varchar(10),op_date,20),7)=@date1 and st_out.inv_no=st_end.
inv_no)
insert st_end (inv_no,quan_in,quan_out) select inv_no,0,sum(quan) from st_out
where left(convert(varchar(10),op_date,20),7)=@date1 and inv_no not in
(select inv_no from st_in where left(convert(varchar(10),op_date,20),7)=@date1)
group by inv_no
在SqlServer調試下通過。

 
多人接受答案了。
 
顶部