use bsjdw
GO
if exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[ZZ]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[ZZ]
go
CREATE PROCEDURE ZZ (@str_XMBH varchar(15) ,@str_ZRZX varchar(50),@str_YF varchar(10),@str_BH varchar(15))
/* [@param_name datatype [= default] [output], ...] */
AS
declare @strsql varchar(8000)
declare @s1 varchar(10)
declare @S2 varchar(10)
declare @S3 varchar(10)
declare @S4 varchar(10)
set @s1='111111'
set @s2='222222'
set @s3='33'
set @s4='%'
--set @strsql=''
set @strSql = 'delete from
XT_ZZ_'+@str_xmbh+' where YF=''' + @str_YF + ''' and ZRZX=''' + @str_zrzx + ''''
print(@strsql)
exec(@strSql)
set @strSql = 'delete from
XT_FHZB_'+@str_xmbh
exec(@strSql)
set @strSql = ' insert into
xt_fhzb_'+@str_xmbh+'( A.kmbh , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , ''222222'' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from
XT_PZB_'+@str_xmbh
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + '%'' and xh like ''' + @str_zrzx + '%'' group by KMBH'
exec (@strSql)
set @strSql = ' insert into
xt_fhzb_'+@str_xmbh+'( A.kmbh , YF , ZRZX , BQJFFS , BQDFFS , BQJFSL , BQDFSL ) '
set @strSql = @strSql + ' select A.kmbh , ''000000'' as YF , ''' + @str_zrzx + ''' as ZRZX '
set @strSql = @strSql + ' , sum(B.NCJFYE) as BQJFFS , sum(B.NCDFYE) as BQDFFS , sum(B.NCJFSL) as BQJFSL , sum(B.NCDFSL) as BQDFSL '
set @strSql = @strSql + ' from
xt_kmb_'+@str_xmbh+' as A left outer join
XT_FHZB_'+@str_xmbh+' as B on B.kmbh like A.kmbh+''%'' '
set @strSql = @strSql + ' group by A.kmbh '
exec (@strSql)
set @strSql = 'delete from
XT_FHZB_'+@str_xmbh+' where YF=''222222'''
exec (@strSql)
set @strSql = ' insert into
xt_fhzb_'+@str_xmbh+' ( A.kmbh , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , ''222222'' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from
XT_PZB_'+@str_xmbh
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + '33'' and xh like ''' + @str_zrzx + '%'' group by KMBH'
exec (@strSql)
set @strSql = ' insert into
xt_fhzb_'+@str_xmbh+' ( A.kmbh , YF , ZRZX , BNJFFS , BNDFFS , BNJFSL , BNDFSL ) '
set @strSql = @strSql + ' select A.kmbh , ''111111'' as YF , ''' + @str_zrzx + ''' as ZRZX '
set @strSql = @strSql + ' , sum(B.NCJFYE) as BNJFFS , sum(B.NCDFYE) as BNDFFS , sum(B.NCJFSL) as BNJFSL , sum(B.NCDFSL) as BNDFSL '
set @strSql = @strSql + ' from
xt_kmb_'+@str_xmbh+' as A left outer join
XT_FHZB_'+@str_xmbh+' as B on B.kmbh like A.kmbh+''%'' '
set @strSql = @strSql + ' where B.YF=''222222'' group by A.kmbh '
exec (@strSql)
set @strSql = 'delete from
XT_HZB_'+@str_xmbh
exec (@strSql)
set @strSql = ' insert into
xt_hzb_'+@str_xmbh+' ( A.kmbh , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , NCJFYE , NCDFYE , QMJFYE , QMDFYE from
XT_kmyeB_'+@str_xmbh
set @strSql = @strSql + ' where kmlb = ''' + @str_zrzx + ''' '
exec (@strSql)
set @strSql = ' insert into
xt_Fhzb_'+@str_xmbh+' ( kmbh , YF , ZRZX , NCJFYE , NCDFYE , NCJFSL , NCDFSL , QCJFYE , QCDFYE ,QCJFSL , QCDFSL , BQJFFS , BQDFFS , BQJFSL , BQDFSL , BNJFFS, BNDFFS, BNJFSL , BNDFSL ,QMJFYE , QMDFYE , QMJFSL ,QMDFSL,YHBH,XMBH ) '
set @strSql = @strSql + ' select B.kmbh , ''' + @str_YF + ''' as YF , ''' + @str_zrzx + ''' as ZRZX '
set @strSql = @strSql + ' , B.NCJFYE as nj , B.NCDFYE as nd , B.NCJFSL as mj , B.NCDFSL as md '
set @strSql = @strSql + ' , B.NCJFYE , B.NCDFYE , B.NCJFSL as QCJFSL , B.NCDFSL as QCDFSL , '
set @strSql = @strSql + ' C.BQJFFS , c.BQDFFS , c.BQJFSL , c.BQDFSL ,'
set @strSql = @strSql + ' D.BNJFFS, d.BNDFFS, d.BNJFSL, d.BNDFSL , 0 AS QMJFYE , 0 AS QMDFYE , 0 AS QMJFSL , 0 AS QMDFSL ,''N'' , ''' + @str_BH + ''' '
set @strSql = @strSql + ' from '
set @strSql = @strSql + ' ( '
set @strSql = @strSql + '
XT_hZB_'+@str_xmbh+' as B '
set @strSql = @strSql + ' left outer join (select * from
XT_FHZB_'+@str_xmbh+' where YF=''000000'') as C on B.kmbh=c.kmbh'
set @strSql = @strSql + ' ) left outer join (select * from
XT_FHZB_'+@str_xmbh+' where YF=''111111'') as D on B.kmbh=D.kmbh '
exec (@strSql)
set @strSql = 'delete from
XT_FHZB_'+@str_xmbh+' where YF<>''' + @str_YF + ''''
exec (@strSql)
set @strSql = ' update
xt_Fhzb_'+@str_xmbh+' set BQJFFS=0 , BQDFFS=0 , BQJFSL=0 , BQDFSL=0 where BQJFFS is null'
set @strSql = @strSql + ' update
xt_Fhzb_'+@str_xmbh+' set BnJFFS=0 , BnDFFS=0 , BnJFSL=0 , BnDFSL=0 where BnJFFS is null'
set @strSql = @strSql + ' update
xt_Fhzb_'+@str_xmbh+' set ncjfye=0 , ncdfye=0 , ncjfsl=0 , ncdfsl=0 , QcJFye=0 , qcdfye=0 , qcjfsl=0 , qcdfsl=0 where qcjfye is null'
exec (@strSql)
set @strSql = ' update
XT_Fhzb_'+@str_xmbh+' set qcjfye=(ncjfye-ncdfye)+(bnjffs-bndffs)-(bqjffs-bqdffs) , qcdfye=0 ,'
set @strSql = @strSql + ' qcjfsl=(ncjfsl-ncdfsl)+(bnjfsl-bndfsl)-(bqjfsl-bqdfsl) , qcdfsl=0 '
set @strSql = @strSql + ' update
XT_fhzb_'+@str_xmbh+' set qcdfye=-qcjfye , qcjfye=0 where qcjfye<0'
set @strSql = @strSql + ' update
XT_fhzb_'+@str_xmbh+' set qcdfsl=-qcjfsl , qcjfsl=0 where qcjfsl<0'
set @strSql = @strSql + ' update
XT_Fhzb_'+@str_xmbh+' set qMjfye=(ncjfye-ncdfye)+(bnjffs-bndffs) , qMdfye=0 ,'
set @strSql = @strSql + ' qMjfsl=(ncjfsl-ncdfsl)+(bnjfsl-bndfsl) , qMdfsl=0 '
set @strSql = @strSql + ' update
XT_Fhzb_'+@str_xmbh+' set qMdfye=-qMjfye , qMjfye=0 where qMjfye<0'
set @strSql = @strSql + ' update
XT_Fhzb_'+@str_xmbh+' set qMdfsl=-qMjfsl , qMjfsl=0 where qMjfsl<0'
exec (@strSql)
set @strSql = ' update XX set XX.KMMC = YY.KMMC from
XT_Fhzb_'+@str_xmbh+' as XX,
XT_KMB_'+@str_xmbh+' as YY where YY.KMBH = XX.KMBH'
exec (@strSql)
set @strSql = ' insert into
xt_ZZ_'+@str_xmbh+' (KMBH , KMMC , ZRZX ,YF ,YHBH, XMBH , NCJFYE ,NCDFYE ,NCJFSL ,NCDFSL , QCJFYE , QCDFYE ,QCJFSL ,QCDFSL ,JFFSE ,DFFSE , JFSL ,DFSL ,JFLJFSE , DFLJFSE ,JFLJSL , DFLJSL ,QMJFYE ,QMDFYE ,QMJFSL ,QMDFSL ) '
set @strSql = @strSql + ' select * from
xt_Fhzb_'+@str_xmbh+' where YF=''' + @str_YF + ''' '
exec (@strSql)
go
-----------------------------------------------------------------------
if exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[FZZ]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[FZZ]
go
CREATE PROCEDURE FZZ (@str_XMBH varchar(15) ,@str_ZRZX varchar(50),@str_YF varchar(10))
/* [@param_name datatype [= default] [output], ...] */
AS
DECLARE @strSql VARCHAR(2000)
declare @s1 varchar(10)
declare @S2 varchar(10)
declare @S3 varchar(10)
declare @S4 varchar(10)
set @s1='111111'
set @s2='222222'
set @s3='33'
set @s4='%'
set @strSql = 'delete from XT_FZB_' + @str_XMBH+ ' where YF=''' + @str_YF + ''' and ZRZX=''' + @str_zrzx + ''''
EXEC(@strSql)
set @strSql = 'delete from XT_FFZB_'+ @str_XMBH
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,WLDWDM ,'''' ,'''' , '''' , '''' , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from
XT_PZB_'+@str_xmbh
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and WLDWDM<>'''' group by KMBH ,WLDWDM '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,WLGRDM ,'''' , '''' , '''' , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from
XT_PZB_'+@str_xmbh
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and WLGRDM<>'''' group by KMBH ,WLGRDM '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,WLBMDM , '''' , '''' , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and WLBMDM<>'''' group by KMBH ,WLBMDM '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,'''' , XJLLMC , '''' , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and XJLLMC<>'''' group by KMBH , XJLLMC '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,'''' , '''' , WLXMDM , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and WLXMDM<>'''' group by KMBH , WLXMDM '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,'''' , '''' , '''' , bz1 ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and bz1<>'''' group by KMBH , bz1 '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,'''' , '''' , '''' , '''' ,bz2 ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and bz2<>'''' group by KMBH ,bz2 '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , WLDWDM ,'''' ,'''' , '''' , '''' , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and wldwdm <>'''' group by KMBH ,WLDWDM '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,WLGRDM ,'''' , '''' , '''' , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and wlGRdm <>'''' group by KMBH ,WLGRDM '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,WLBMDM , '''' , '''' , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and wlbmdm <>'''' group by KMBH ,WLBMDM '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,'''' , XJLLMC , '''' , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and xjllmc <>'''' group by KMBH , XJLLMC '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,'''' , '''' , WLXMDM , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and wlxmdm <>'''' group by KMBH , WLXMDM '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,'''' , '''' , '''' , bz1 ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and bz1 <>'''' group by KMBH , bz1'
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,'''' , '''' , '''' , '''' ,bz2 ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and bz2 <>'''' group by KMBH ,bz2'
EXEC(@strSql)
set @strSql = ' update xt_FFzb_' + @str_XMBH+ ' set WLDWDM='''+''' where WLDWDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set WLGRDM='''+''' where WLGRDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set WLBMDM='''+''' where WLBMDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set WLXMDM='''+''' where WLXMDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set XJLLDM='''+''' where XJLLDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set CPZXDM='''+''' where CPZXDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set CBZXDM='''+''' where CBZXDM is null'
EXEC(@strSql)
SET @strSql = ' insert into xt_FFzb_' + @str_XMBH + ' ( kmbh , YF , ZRZX ,WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , NCJFYE , NCDFYE , NCJFSL , NCDFSL , QCJFYE , QCDFYE ,QCJFSL , QCDFSL , BQJFFS , BQDFFS , BQJFSL , BQDFSL , BNJFFS, BNDFFS, BNJFSL , BNDFSL ,QMJFYE , QMDFYE , QMJFSL ,QMDFSL ) '
set @strSql = @strSql + ' select B.kmbh , ''' + @str_YF + ''' as YF , ''' + @str_zrzx + ''' as ZRZX , b.WLDWDM ,b.WLGRDM , b.WLBMDM ,b.XJLLDM,b.WLXMDM ,B.CPZXDM ,B.CBZXDM '
set @strSql = @strSql + ' , B.NCJFYE as nj , B.NCDFYE as nd , B.NCJFSL as mj , B.NCDFSL as md '
set @strSql = @strSql + ' , B.NCJFYE , B.NCDFYE , B.NCJFSL , B.NCJFSL , '
set @strSql = @strSql + ' C.NCJFYE , c.NCDFYE , c.NCJFSL , c.NCDFSL ,'
set @strSql = @strSql + ' D.NCJFYE , d.NCDFYE, d.NCJFSL, d.NCDFSL , 0 AS QMJFYE , 0 AS QMDFYE , 0 AS QMJFSL , 0 AS QMDFSL '
set @strSql = @strSql + ' from '
set @strSql = @strSql + ' ( '
set @strSql = @strSql + ' ( select * from XT_LFZB_' + @str_XMBH + ' where ZRZX=''' + @str_zrzx + ''' ) as B '
set @strSql = @strSql + ' left OUTER join (select * from XT_FFZB_' + @str_XMBH + ' where
YF='''+@S1+''') as C on B.kmbh=c.kmbh and B.WLDWDM=C.WLDWDM and b.WLGRDM=C.WLGRDM and b.WLBMDM=C.WLBMDM and b.XJLLDM=C.XJLLDM and b.WLXMDM=C.WLXMDM and b.CPZXDM=C.CPZXDM and b.CBZXDM=C.CBZXDM '
set @strSql = @strSql + ' ) left OUTER join (select * from XT_FFZB_' + @str_XMBH + ' where
YF='''+@S2+''') as D on B.kmbh=D.kmbh and B.WLDWDM=D.WLDWDM and b.WLGRDM=D.WLGRDM and b.WLBMDM=D.WLBMDM and b.XJLLDM=D.XJLLDM and b.WLXMDM=D.WLXMDM and b.CPZXDM=D.CPZXDM and b.CBZXDM=D.CBZXDM '
EXEC(@strSql)
SET @strSql = 'delete from XT_FfZB_' + @str_XMBH + ' where YF<>''' + @str_YF + ''''
EXEC(@strSql)
SET @strSql = ' update xt_FFzb_' + @str_XMBH + ' set BQJFFS=0 , BQDFFS=0 , BQJFSL=0 , BQDFSL=0 where BQJFFS is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set BnJFFS=0 , BnDFFS=0 , BnJFSL=0 , BnDFSL=0 where BnJFFS is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set ncjfye=0 , ncdfye=0 , ncjfsl=0 , ncdfsl=0 , QcJFye=0 , qcdfye=0 , qcjfsl=0 , qcdfsl=0 where qcjfye is null'
EXEC(@strSql)
SET @strSql = ' update XT_FFzb_' + @str_XMBH + ' set qcjfye=(ncjfye-ncdfye)+(bnjffs-bndffs)-(bqjffs-bqdffs) , qcdfye=0 ,'
set @strSql = @strSql + ' qcjfsl=(ncjfsl-ncdfsl)+(bnjfsl-bndfsl)-(bqjfsl-bqdfsl) , qcdfsl=0 '
set @strSql = @strSql + ' update XT_fFzb_' + @str_XMBH + ' set qcdfye=-qcjfye , qcjfye=0 where qcjfye<0'
set @strSql = @strSql + ' update XT_fFzb_' + @str_XMBH + ' set qcdfsl=-qcjfsl , qcjfsl=0 where qcjfsl<0'
set @strSql = @strSql + ' update XT_FFzb_' + @str_XMBH + ' set qMjfye=(ncjfye-ncdfye)+(bnjffs-bndffs) , qMdfye=0 ,'
set @strSql = @strSql + ' qMjfsl=(ncjfsl-ncdfsl)+(bnjfsl-bndfsl) , qMdfsl=0 '
set @strSql = @strSql + ' update XT_FFzb_' + @str_XMBH + ' set qMdfye=-qMjfye , qmjfye=0 where qMjfye<0'
set @strSql = @strSql + ' update XT_FFzb_' + @str_XMBH + ' set qMdfsl=-qMjfsl , qmjfsl=0 where qMjfsl<0'
EXEC(@strSql)
SET @strSql = ' update xt_FFzb_' + @str_XMBH + ' set WLDWDM='''' where WLDWDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set WLGRDM='''' where WLGRDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set WLBMDM='''' where WLBMDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set WLXMDM='''' where WLXMDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set XJLLDM='''' where XJLLDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set CPZXDM='''' where CPZXDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set CBZXDM='''' where CBZXDM is null'
EXEC(@strSql)
SET @strSql = ' update XX set XX.KMMC = YY.KMMC from XT_FFzb_' + @str_XMBH + ' as XX, XT_KMB_' + @str_XMBH + ' as YY where YY.KMBH = XX.KMBH'
EXEC(@strSql)
SET @strSql = ' insert into xt_Fzb_' + @str_XMBH
set @strSql = @strSql + ' select * from xt_FFzb_' + @str_XMBH + ' where YF=''' + @str_YF + ''''
EXEC(@strSql)
go
---------------------------------------------------------------------------------
use system
GO
if exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[ZZ]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[ZZ]
go
CREATE PROCEDURE ZZ (@str_XMBH varchar(15) ,@str_ZRZX varchar(50),@str_YF varchar(10),@str_BH varchar(15))
/* [@param_name datatype [= default] [output], ...] */
AS
declare @strsql varchar(8000)
declare @s1 varchar(10)
declare @S2 varchar(10)
declare @S3 varchar(10)
declare @S4 varchar(10)
set @s1='111111'
set @s2='222222'
set @s3='33'
set @s4='%'
--set @strsql=''
set @strSql = 'delete from
XT_ZZ_'+@str_xmbh+' where YF=''' + @str_YF + ''' and ZRZX=''' + @str_zrzx + ''''
print(@strsql)
exec(@strSql)
set @strSql = 'delete from
XT_FHZB_'+@str_xmbh
exec(@strSql)
set @strSql = ' insert into
xt_fhzb_'+@str_xmbh+'( A.kmbh , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , ''222222'' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from
XT_PZB_'+@str_xmbh
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + '%'' and xh like ''' + @str_zrzx + '%'' group by KMBH'
exec (@strSql)
set @strSql = ' insert into
xt_fhzb_'+@str_xmbh+'( A.kmbh , YF , ZRZX , BQJFFS , BQDFFS , BQJFSL , BQDFSL ) '
set @strSql = @strSql + ' select A.kmbh , ''000000'' as YF , ''' + @str_zrzx + ''' as ZRZX '
set @strSql = @strSql + ' , sum(B.NCJFYE) as BQJFFS , sum(B.NCDFYE) as BQDFFS , sum(B.NCJFSL) as BQJFSL , sum(B.NCDFSL) as BQDFSL '
set @strSql = @strSql + ' from
xt_kmb_'+@str_xmbh+' as A left outer join
XT_FHZB_'+@str_xmbh+' as B on B.kmbh like A.kmbh+''%'' '
set @strSql = @strSql + ' group by A.kmbh '
exec (@strSql)
set @strSql = 'delete from
XT_FHZB_'+@str_xmbh+' where YF=''222222'''
exec (@strSql)
set @strSql = ' insert into
xt_fhzb_'+@str_xmbh+' ( A.kmbh , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , ''222222'' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from
XT_PZB_'+@str_xmbh
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + '33'' and xh like ''' + @str_zrzx + '%'' group by KMBH'
exec (@strSql)
set @strSql = ' insert into
xt_fhzb_'+@str_xmbh+' ( A.kmbh , YF , ZRZX , BNJFFS , BNDFFS , BNJFSL , BNDFSL ) '
set @strSql = @strSql + ' select A.kmbh , ''111111'' as YF , ''' + @str_zrzx + ''' as ZRZX '
set @strSql = @strSql + ' , sum(B.NCJFYE) as BNJFFS , sum(B.NCDFYE) as BNDFFS , sum(B.NCJFSL) as BNJFSL , sum(B.NCDFSL) as BNDFSL '
set @strSql = @strSql + ' from
xt_kmb_'+@str_xmbh+' as A left outer join
XT_FHZB_'+@str_xmbh+' as B on B.kmbh like A.kmbh+''%'' '
set @strSql = @strSql + ' where B.YF=''222222'' group by A.kmbh '
exec (@strSql)
set @strSql = 'delete from
XT_HZB_'+@str_xmbh
exec (@strSql)
set @strSql = ' insert into
xt_hzb_'+@str_xmbh+' ( A.kmbh , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , NCJFYE , NCDFYE , QMJFYE , QMDFYE from
XT_kmyeB_'+@str_xmbh
set @strSql = @strSql + ' where kmlb = ''' + @str_zrzx + ''' '
exec (@strSql)
set @strSql = ' insert into
xt_Fhzb_'+@str_xmbh+' ( kmbh , YF , ZRZX , NCJFYE , NCDFYE , NCJFSL , NCDFSL , QCJFYE , QCDFYE ,QCJFSL , QCDFSL , BQJFFS , BQDFFS , BQJFSL , BQDFSL , BNJFFS, BNDFFS, BNJFSL , BNDFSL ,QMJFYE , QMDFYE , QMJFSL ,QMDFSL,YHBH,XMBH ) '
set @strSql = @strSql + ' select B.kmbh , ''' + @str_YF + ''' as YF , ''' + @str_zrzx + ''' as ZRZX '
set @strSql = @strSql + ' , B.NCJFYE as nj , B.NCDFYE as nd , B.NCJFSL as mj , B.NCDFSL as md '
set @strSql = @strSql + ' , B.NCJFYE , B.NCDFYE , B.NCJFSL as QCJFSL , B.NCDFSL as QCDFSL , '
set @strSql = @strSql + ' C.BQJFFS , c.BQDFFS , c.BQJFSL , c.BQDFSL ,'
set @strSql = @strSql + ' D.BNJFFS, d.BNDFFS, d.BNJFSL, d.BNDFSL , 0 AS QMJFYE , 0 AS QMDFYE , 0 AS QMJFSL , 0 AS QMDFSL ,''N'' , ''' + @str_BH + ''' '
set @strSql = @strSql + ' from '
set @strSql = @strSql + ' ( '
set @strSql = @strSql + '
XT_hZB_'+@str_xmbh+' as B '
set @strSql = @strSql + ' left outer join (select * from
XT_FHZB_'+@str_xmbh+' where YF=''000000'') as C on B.kmbh=c.kmbh'
set @strSql = @strSql + ' ) left outer join (select * from
XT_FHZB_'+@str_xmbh+' where YF=''111111'') as D on B.kmbh=D.kmbh '
exec (@strSql)
set @strSql = 'delete from
XT_FHZB_'+@str_xmbh+' where YF<>''' + @str_YF + ''''
exec (@strSql)
set @strSql = ' update
xt_Fhzb_'+@str_xmbh+' set BQJFFS=0 , BQDFFS=0 , BQJFSL=0 , BQDFSL=0 where BQJFFS is null'
set @strSql = @strSql + ' update
xt_Fhzb_'+@str_xmbh+' set BnJFFS=0 , BnDFFS=0 , BnJFSL=0 , BnDFSL=0 where BnJFFS is null'
set @strSql = @strSql + ' update
xt_Fhzb_'+@str_xmbh+' set ncjfye=0 , ncdfye=0 , ncjfsl=0 , ncdfsl=0 , QcJFye=0 , qcdfye=0 , qcjfsl=0 , qcdfsl=0 where qcjfye is null'
exec (@strSql)
set @strSql = ' update
XT_Fhzb_'+@str_xmbh+' set qcjfye=(ncjfye-ncdfye)+(bnjffs-bndffs)-(bqjffs-bqdffs) , qcdfye=0 ,'
set @strSql = @strSql + ' qcjfsl=(ncjfsl-ncdfsl)+(bnjfsl-bndfsl)-(bqjfsl-bqdfsl) , qcdfsl=0 '
set @strSql = @strSql + ' update
XT_fhzb_'+@str_xmbh+' set qcdfye=-qcjfye , qcjfye=0 where qcjfye<0'
set @strSql = @strSql + ' update
XT_fhzb_'+@str_xmbh+' set qcdfsl=-qcjfsl , qcjfsl=0 where qcjfsl<0'
set @strSql = @strSql + ' update
XT_Fhzb_'+@str_xmbh+' set qMjfye=(ncjfye-ncdfye)+(bnjffs-bndffs) , qMdfye=0 ,'
set @strSql = @strSql + ' qMjfsl=(ncjfsl-ncdfsl)+(bnjfsl-bndfsl) , qMdfsl=0 '
set @strSql = @strSql + ' update
XT_Fhzb_'+@str_xmbh+' set qMdfye=-qMjfye , qMjfye=0 where qMjfye<0'
set @strSql = @strSql + ' update
XT_Fhzb_'+@str_xmbh+' set qMdfsl=-qMjfsl , qMjfsl=0 where qMjfsl<0'
exec (@strSql)
set @strSql = ' update XX set XX.KMMC = YY.KMMC from
XT_Fhzb_'+@str_xmbh+' as XX,
XT_KMB_'+@str_xmbh+' as YY where YY.KMBH = XX.KMBH'
exec (@strSql)
set @strSql = ' insert into
xt_ZZ_'+@str_xmbh+' (KMBH , KMMC , ZRZX ,YF ,YHBH, XMBH , NCJFYE ,NCDFYE ,NCJFSL ,NCDFSL , QCJFYE , QCDFYE ,QCJFSL ,QCDFSL ,JFFSE ,DFFSE , JFSL ,DFSL ,JFLJFSE , DFLJFSE ,JFLJSL , DFLJSL ,QMJFYE ,QMDFYE ,QMJFSL ,QMDFSL ) '
set @strSql = @strSql + ' select * from
xt_Fhzb_'+@str_xmbh+' where YF=''' + @str_YF + ''' '
exec (@strSql)
go
--------------------------------------------------------------------------
if exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[FZZ]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[FZZ]
go
CREATE PROCEDURE FZZ (@str_XMBH varchar(15) ,@str_ZRZX varchar(50),@str_YF varchar(10))
/* [@param_name datatype [= default] [output], ...] */
AS
DECLARE @strSql VARCHAR(2000)
declare @s1 varchar(10)
declare @S2 varchar(10)
declare @S3 varchar(10)
declare @S4 varchar(10)
set @s1='111111'
set @s2='222222'
set @s3='33'
set @s4='%'
set @strSql = 'delete from XT_FZB_' + @str_XMBH+ ' where YF=''' + @str_YF + ''' and ZRZX=''' + @str_zrzx + ''''
EXEC(@strSql)
set @strSql = 'delete from XT_FFZB_'+ @str_XMBH
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,WLDWDM ,'''' ,'''' , '''' , '''' , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from
XT_PZB_'+@str_xmbh
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and WLDWDM<>'''' group by KMBH ,WLDWDM '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,WLGRDM ,'''' , '''' , '''' , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from
XT_PZB_'+@str_xmbh
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and WLGRDM<>'''' group by KMBH ,WLGRDM '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,WLBMDM , '''' , '''' , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and WLBMDM<>'''' group by KMBH ,WLBMDM '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,'''' , XJLLMC , '''' , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and XJLLMC<>'''' group by KMBH , XJLLMC '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,'''' , '''' , WLXMDM , '''' ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and WLXMDM<>'''' group by KMBH , WLXMDM '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,'''' , '''' , '''' , bz1 ,'''' ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and bz1<>'''' group by KMBH , bz1 '
EXEC(@strSql)
set @strSql = ' insert into xt_fFzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH ,'''' ,'''' ,'''' , '''' , '''' , '''' ,bz2 ,
'''+@s1+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq like ''' + @str_YF + @s4 +''' and xh like ''' + @str_zrzx + @s4 +''' and bz2<>'''' group by KMBH ,bz2 '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , WLDWDM ,'''' ,'''' , '''' , '''' , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and wldwdm <>'''' group by KMBH ,WLDWDM '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,WLGRDM ,'''' , '''' , '''' , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and wlGRdm <>'''' group by KMBH ,WLGRDM '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,WLBMDM , '''' , '''' , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and wlbmdm <>'''' group by KMBH ,WLBMDM '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,'''' , XJLLMC , '''' , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and xjllmc <>'''' group by KMBH , XJLLMC '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,'''' , '''' , WLXMDM , '''' ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and wlxmdm <>'''' group by KMBH , WLXMDM '
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,'''' , '''' , '''' , bz1 ,'''' ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and bz1 <>'''' group by KMBH , bz1'
EXEC(@strSql)
set @strSql = ' insert into xt_ffzb_' + @str_XMBH+ ' ( kmbh , WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , YF , NCJFYE , NCDFYE , NCJFSL , NCDFSL ) '
set @strSql = @strSql + ' select KMBH , '''' ,'''' ,'''' , '''' , '''' , '''' ,bz2 ,
'''+@s2+''' AS YF , sum(JFJE) AS NCJFYE ,sum(DFJE) AS NCDFYE ,sum(JFSL) AS NCJFSL ,sum(DFSL) AS NCDFSL from XT_PZB_' + @str_XMBH
set @strSql = @strSql + ' where pzrq <= ''' + @str_YF + @s3+''' and xh like ''' + @str_zrzx + @s4 +''' and bz2 <>'''' group by KMBH ,bz2'
EXEC(@strSql)
set @strSql = ' update xt_FFzb_' + @str_XMBH+ ' set WLDWDM='''+''' where WLDWDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set WLGRDM='''+''' where WLGRDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set WLBMDM='''+''' where WLBMDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set WLXMDM='''+''' where WLXMDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set XJLLDM='''+''' where XJLLDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set CPZXDM='''+''' where CPZXDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH+ ' set CBZXDM='''+''' where CBZXDM is null'
EXEC(@strSql)
SET @strSql = ' insert into xt_FFzb_' + @str_XMBH + ' ( kmbh , YF , ZRZX ,WLDWDM ,WLGRDM , WLBMDM ,XJLLDM,WLXMDM ,CPZXDM ,CBZXDM , NCJFYE , NCDFYE , NCJFSL , NCDFSL , QCJFYE , QCDFYE ,QCJFSL , QCDFSL , BQJFFS , BQDFFS , BQJFSL , BQDFSL , BNJFFS, BNDFFS, BNJFSL , BNDFSL ,QMJFYE , QMDFYE , QMJFSL ,QMDFSL ) '
set @strSql = @strSql + ' select B.kmbh , ''' + @str_YF + ''' as YF , ''' + @str_zrzx + ''' as ZRZX , b.WLDWDM ,b.WLGRDM , b.WLBMDM ,b.XJLLDM,b.WLXMDM ,B.CPZXDM ,B.CBZXDM '
set @strSql = @strSql + ' , B.NCJFYE as nj , B.NCDFYE as nd , B.NCJFSL as mj , B.NCDFSL as md '
set @strSql = @strSql + ' , B.NCJFYE , B.NCDFYE , B.NCJFSL , B.NCJFSL , '
set @strSql = @strSql + ' C.NCJFYE , c.NCDFYE , c.NCJFSL , c.NCDFSL ,'
set @strSql = @strSql + ' D.NCJFYE , d.NCDFYE, d.NCJFSL, d.NCDFSL , 0 AS QMJFYE , 0 AS QMDFYE , 0 AS QMJFSL , 0 AS QMDFSL '
set @strSql = @strSql + ' from '
set @strSql = @strSql + ' ( '
set @strSql = @strSql + ' ( select * from XT_LFZB_' + @str_XMBH + ' where ZRZX=''' + @str_zrzx + ''' ) as B '
set @strSql = @strSql + ' left OUTER join (select * from XT_FFZB_' + @str_XMBH + ' where
YF='''+@S1+''') as C on B.kmbh=c.kmbh and B.WLDWDM=C.WLDWDM and b.WLGRDM=C.WLGRDM and b.WLBMDM=C.WLBMDM and b.XJLLDM=C.XJLLDM and b.WLXMDM=C.WLXMDM and b.CPZXDM=C.CPZXDM and b.CBZXDM=C.CBZXDM '
set @strSql = @strSql + ' ) left OUTER join (select * from XT_FFZB_' + @str_XMBH + ' where
YF='''+@S2+''') as D on B.kmbh=D.kmbh and B.WLDWDM=D.WLDWDM and b.WLGRDM=D.WLGRDM and b.WLBMDM=D.WLBMDM and b.XJLLDM=D.XJLLDM and b.WLXMDM=D.WLXMDM and b.CPZXDM=D.CPZXDM and b.CBZXDM=D.CBZXDM '
EXEC(@strSql)
SET @strSql = 'delete from XT_FfZB_' + @str_XMBH + ' where YF<>''' + @str_YF + ''''
EXEC(@strSql)
SET @strSql = ' update xt_FFzb_' + @str_XMBH + ' set BQJFFS=0 , BQDFFS=0 , BQJFSL=0 , BQDFSL=0 where BQJFFS is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set BnJFFS=0 , BnDFFS=0 , BnJFSL=0 , BnDFSL=0 where BnJFFS is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set ncjfye=0 , ncdfye=0 , ncjfsl=0 , ncdfsl=0 , QcJFye=0 , qcdfye=0 , qcjfsl=0 , qcdfsl=0 where qcjfye is null'
EXEC(@strSql)
SET @strSql = ' update XT_FFzb_' + @str_XMBH + ' set qcjfye=(ncjfye-ncdfye)+(bnjffs-bndffs)-(bqjffs-bqdffs) , qcdfye=0 ,'
set @strSql = @strSql + ' qcjfsl=(ncjfsl-ncdfsl)+(bnjfsl-bndfsl)-(bqjfsl-bqdfsl) , qcdfsl=0 '
set @strSql = @strSql + ' update XT_fFzb_' + @str_XMBH + ' set qcdfye=-qcjfye , qcjfye=0 where qcjfye<0'
set @strSql = @strSql + ' update XT_fFzb_' + @str_XMBH + ' set qcdfsl=-qcjfsl , qcjfsl=0 where qcjfsl<0'
set @strSql = @strSql + ' update XT_FFzb_' + @str_XMBH + ' set qMjfye=(ncjfye-ncdfye)+(bnjffs-bndffs) , qMdfye=0 ,'
set @strSql = @strSql + ' qMjfsl=(ncjfsl-ncdfsl)+(bnjfsl-bndfsl) , qMdfsl=0 '
set @strSql = @strSql + ' update XT_FFzb_' + @str_XMBH + ' set qMdfye=-qMjfye , qmjfye=0 where qMjfye<0'
set @strSql = @strSql + ' update XT_FFzb_' + @str_XMBH + ' set qMdfsl=-qMjfsl , qmjfsl=0 where qMjfsl<0'
EXEC(@strSql)
SET @strSql = ' update xt_FFzb_' + @str_XMBH + ' set WLDWDM='''' where WLDWDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set WLGRDM='''' where WLGRDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set WLBMDM='''' where WLBMDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set WLXMDM='''' where WLXMDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set XJLLDM='''' where XJLLDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set CPZXDM='''' where CPZXDM is null'
set @strSql = @strSql + ' update xt_FFzb_' + @str_XMBH + ' set CBZXDM='''' where CBZXDM is null'
EXEC(@strSql)
SET @strSql = ' update XX set XX.KMMC = YY.KMMC from XT_FFzb_' + @str_XMBH + ' as XX, XT_KMB_' + @str_XMBH + ' as YY where YY.KMBH = XX.KMBH'
EXEC(@strSql)
SET @strSql = ' insert into xt_Fzb_' + @str_XMBH
set @strSql = @strSql + ' select * from xt_FFzb_' + @str_XMBH + ' where YF=''' + @str_YF + ''''
EXEC(@strSql)
go