| 发表于:2007-05-08 15:37:2530楼 得分:0 |
if exists (select * from sysobjects where name = 'sp_test ' and type = 'p ') drop procedure sp_test go substring() create procedure sp_test(@date char(8),@dqbh char(20)) as begin if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsa] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsa] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsb] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsb] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsc] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsc] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsaa] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsaa] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsbb] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsbb] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smscc] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smscc] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsd] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsd] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smse] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smse] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsf] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsf] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsg] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsg] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsh] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsh] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsi] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsi] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsaaa] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsaaa] if exists (select * from dbo.sysobjects where id = object_id(n '[lc0059999].[smsbbb] ') and objectproperty(id, n 'isusertable ') = 1) drop table [lc0059999].[smsbbb] /*日报表smsc*/ select w.zwdqzd_dqmc,z.zwwldw_dqbh,z.zwwldw_dwbh,z.zwwldw_dwmc,sum(a.xstdmx_zsl) as xstdmx_zsl_day, sum(a.xstdmx_bhse) as xstdmx_bhse_day into smsa from ((xstdmx as a inner join xstd as b on a.xstdmx_tdls = b.xstd_tdls) left join zwwldw as z on z.zwwldw_dwbh=b.xstd_shdkh) inner join zwdqzd as w on w.zwdqzd_dqbh=z.zwwldw_dqbh where b.xstd_djrq=@date group by w.zwdqzd_dqmc,z.zwwldw_dqbh,z.zwwldw_dwbh,z.zwwldw_dwmc select w.zwdqzd_dqmc,z.zwwldw_dqbh,z.zwwldw_dwbh,z.zwwldw_dwmc,sum(c.xshk_bhke) as xshk_bhke_day into smsb from (xshk as c inner join zwwldw as z on z.zwwldw_dwbh=c.xshk_shdkh) inner join zwdqzd as w on w.zwdqzd_dqbh=z.zwwldw_dqbh where c.xshk_djrq=@date group by w.zwdqzd_dqmc,z.zwwldw_dqbh,z.zwwldw_dwbh,z.zwwldw_dwmc select a.zwdqzd_dqmc,a.zwwldw_dqbh,a.zwwldw_dwbh,a.zwwldw_dwmc,a.xstdmx_zsl_day,a.xstdmx_bhse_day,b.xshk_bhke_day into smsc from smsa as a left join smsb as b on b.zwwldw_dwbh=a.zwwldw_dwbh insert into smsc select b.zwdqzd_dqmc,b.zwwldw_dqbh,b.zwwldw_dwbh,b.zwwldw_dwmc,a.xstdmx_zsl_day,a.xstdmx_bhse_day,b.xshk_bhke_day from smsb as b left join smsa as a on b.zwwldw_dwbh=a.zwwldw_dwbh where b.zwwldw_dwbh not in (select zwwldw_dwbh from smsc) /*月报表smscc*/ select w.zwdqzd_dqmc,z.zwwldw_dqbh,z.zwwldw_dwbh,z.zwwldw_dwmc,sum(a.xstdmx_zsl) as xstdmx_zsl_m, sum(a.xstdmx_bhse) as xstdmx_bhse_m into smsaa from ((xstdmx as a inner join xstd as b on a.xstdmx_tdls = b.xstd_tdls) left join zwwldw as z on z.zwwldw_dwbh=b.xstd_shdkh) inner join zwdqzd as w on w.zwdqzd_dqbh=z.zwwldw_dqbh where b.xstd_djrq <=@date and b.xstd_djrq> =left(@date,6)+ '01 ' group by w.zwdqzd_dqmc,z.zwwldw_dqbh,z.zwwldw_dwbh,z.zwwldw_dwmc select w.zwdqzd_dqmc,z.zwwldw_dqbh,z.zwwldw_dwbh,z.zwwldw_dwmc,sum(c.xshk_bhke) as xshk_bhke_m into smsbb from (xshk as c inner join zwwldw as z on z.zwwldw_dwbh=c.xshk_shdkh) inner join zwdqzd as w on w.zwdqzd_dqbh=z.zwwldw_dqbh where c.xshk_djrq <=@date and c.xshk_djrq> =left(@date,6)+ '01 ' group by w.zwdqzd_dqmc,z.zwwldw_dqbh,z.zwwldw_dwbh,z.zwwldw_dwmc select a.zwdqzd_dqmc,a.zwwldw_dqbh,a.zwwldw_dwbh,a.zwwldw_dwmc,a.xstdmx_zsl_m,a.xstdmx_bhse_m,b.xshk_bhke_m into smscc from smsaa as a left join smsbb as b on b.zwwldw_dwbh=a.zwwldw_dwbh insert into smscc select b.zwdqzd_dqmc,b.zwwldw_dqbh,b.zwwldw_dwbh,b.zwwldw_dwmc,a.xstdmx_zsl_m,a.xstdmx_bhse_m,b.xshk_bhke_m from smsbb as b left join smsaa as a on b.zwwldw_dwbh=a.zwwldw_dwbh where b.zwwldw_dwbh not in (select zwwldw_dwbh from smscc) /*合并日报表和月报表smsd*/ select cc.zwdqzd_dqmc,cc.zwwldw_dqbh,cc.zwwldw_dwbh,cc.zwwldw_dwmc,c.xstdmx_zsl_day,c.xstdmx_bhse_day,c.xshk_bhke_day, cc.xstdmx_zsl_m,cc.xstdmx_bhse_m,cc.xshk_bhke_m into smsd from smscc as cc left join smsc as c on c.zwwldw_dwbh=cc.zwwldw_dwbh /*合同应收款smse*/ select hmhtgy_dwbh,hmhtgy_htje into smse from hmhtgy where hmhtgy_qdrq <=@date /*合并日报表和月报表后加入合同应收款smsf*/ select d.zwdqzd_dqmc,d.zwwldw_dqbh,d.zwwldw_dwbh,d.zwwldw_dwmc,d.xstdmx_zsl_day,d.xstdmx_bhse_day,d.xshk_bhke_day, d.xstdmx_zsl_m,d.xstdmx_bhse_m,d.xshk_bhke_m,h.hmhtgy_htje into smsf from smsd as d left join smse as h on h.hmhtgy_dwbh=d.zwwldw_dwbh /*合同实收款*/ select f.xsfp_shdkh,sum(x.xsfpmx_bhke) as xsfpmx_bhke into smsg from xsfpmx as x inner join xsfp as f on f.xsfp_fpls=x.xsfpmx_fpls where xsfp_djrq <=@date group by f.xsfp_shdkh /*合同余额smsh*/ select e.hmhtgy_dwbh,(e.hmhtgy_htje-g.xsfpmx_bhke) htye into smsh from smse as e left join smsg as g on g.xsfp_shdkh=e.hmhtgy_dwbh /*smsf加入余额*/ select d.zwdqzd_dqmc,d.zwwldw_dqbh,d.zwwldw_dwbh,d.zwwldw_dwmc,d.xstdmx_zsl_day,d.xstdmx_bhse_day,d.xshk_bhke_day, d.xstdmx_zsl_m,d.xstdmx_bhse_m,d.xshk_bhke_m,d.hmhtgy_htje,h.htye into smsi from smsf as d left join smsh as h on h.hmhtgy_dwbh=d.zwwldw_dwbh | | |
|