石
石嶷山友
Unregistered / Unconfirmed
GUEST, unregistred user!
CREATE PROCEDURE GMSYRBB_PRO ----公墓收入日报表<br><br>@RQ1 smalldatetime,<br>@RQ2 smalldatetime,<br>@CZYXM nvarchar(16),<br>@MQLB int<br><br> AS<br><br>DECLARE <br>@I int,<br>@FPHM nvarchar(50),<br>@QH nvarchar(50),<br>@PH nvarchar(50),<br>@MWBH nvarchar(50),<br>@XMMC nvarchar(24),<br>@MK money,<br>@CXF money,<br>@KZF money,<br>@GLWXF money,<br>@ZXF money,<br>@QTFY money,<br>@FLAG smallint,<br>@LBXM nvarchar(16),<br>@HJ money,<br>@RQ smalldatetime,<br>@SKDH nvarchar(12),<br>@SL int,<br>@MWID int,<br>@FP nvarchar(50),<br>@TMRQ smalldatetime<br><br>DELETE FROM GMSYRBB_RP WHERE CZYXM=@CZYXM<br><br>SELECT @I=1<br><br><br>IF @MQLB=0 OR @MQLB=1<br>BEGIN<br> DECLARE FPSY CURSOR FOR SELECT DISTINCT LBXM FROM MWFYYLB WHERE RQ BETWEEN @RQ1 AND @RQ2 AND MQLB=@MQLB ORDER BY LBXM<br>END<br>ELSE<br>BEGIN<br> DECLARE FPSY CURSOR FOR SELECT DISTINCT LBXM FROM MWFYYLB WHERE RQ BETWEEN @RQ1 AND @RQ2 ORDER BY LBXM<br>END<br><br>OPEN FPSY<br>FETCH NEXT FROM FPSY INTO @LBXM<br>WHILE @@FETCH_STATUS = 0<br><br>BEGIN<br><br> IF @MQLB=0 OR @MQLB=1<br> BEGIN<br> DECLARE RQ_CUR CURSOR FOR SELECT DISTINCT RQ FROM MWFYYLB WHERE RQ BETWEEN @RQ1 AND @RQ2 AND LBXM=@LBXM AND MQLB=@MQLB ORDER BY RQ<br> END<br> ELSE<br> BEGIN<br> DECLARE RQ_CUR CURSOR FOR SELECT DISTINCT RQ FROM MWFYYLB WHERE RQ BETWEEN @RQ1 AND @RQ2 AND LBXM=@LBXM ORDER BY RQ<br> END<br><br> OPEN RQ_CUR<br> FETCH NEXT FROM RQ_CUR INTO @RQ<br> WHILE @@FETCH_STATUS=0<br><br> BEGIN <br> <br><br> IF @MQLB=0 OR @MQLB=1 <br> BEGIN<br> DECLARE FP CURSOR FOR SELECT DISTINCT FPHM FROM MWFYYLB WHERE FPHM IN(SELECT FPHM FROM MWFYYLB WHERE RQ=@RQ AND LBXM=@LBXM AND MQLB=@MQLB) OR FPHM IN (SELECT FPHM FROM MWFYYLB WHERE TMRQ=@RQ AND LBXM=@LBXM AND MQLB=@MQLB) ORDER BY FPHM<br> END<br> ELSE<br> BEGIN<br> DECLARE FP CURSOR FOR SELECT DISTINCT FPHM FROM MWFYYLB WHERE FPHM IN(SELECT FPHM FROM MWFYYLB WHERE RQ=@RQ AND LBXM=@LBXM  OR FPHM IN (SELECT FPHM FROM MWFYYLB WHERE TMRQ=@RQ AND LBXM=@LBXM) ORDER BY FPHM<br> END <br> <br> OPEN FP<br> FETCH NEXT FROM FP INTO @FPHM<br><br> WHILE @@FETCH_STATUS=0<br> BEGIN <br><br> IF @MQLB=0 OR @MQLB=1 <br> BEGIN <br> SELECT @MK=SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%墓地使用费%' AND RQ=@RQ AND FPHM=@FPHM AND MQLB=@MQLB AND LBXM=@LBXM<br> SELECT @SL=COUNT(DISTINCT MWID) FROM MWFYYLB WHERE XMMC='墓地使用费' AND RQ=@RQ AND FPHM=@FPHM AND LBXM=@LBXM AND MQLB=@MQLB AND BCSK>0<br> SELECT @CXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC='瓷像费' AND RQ=@RQ AND FPHM=@FPHM AND MQLB=@MQLB AND LBXM=@LBXM<br> SELECT @KZF= SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%刻字费%' AND RQ=@RQ AND FPHM=@FPHM AND MQLB=@MQLB AND LBXM=@LBXM<br> SELECT @ZXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC='装修费' AND RQ=@RQ AND FPHM=@FPHM AND MQLB=@MQLB AND LBXM=@LBXM<br> SELECT @GLWXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%管理费%' AND RQ=@RQ AND FPHM=@FPHM AND MQLB=@MQLB AND LBXM=@LBXM<br> SELECT @HJ=SUM(BCSK) FROM MWFYYLB WHERE RQ=@RQ AND FPHM=@FPHM AND MQLB=@MQLB AND LBXM=@LBXM<br><br> IF @HJ IS NULL SELECT @HJ=0<br> IF @MK IS NULL SELECT @MK=0<br> IF @GLWXF IS NULL SELECT @GLWXF=0<br> IF @CXF IS NULL SELECT @CXF=0<br> IF @KZF IS NULL SELECT @KZF=0<br> IF @ZXF IS NULL SELECT @ZXF=0<br><br> SELECT @QTFY=@HJ-@MK-@GLWXF-@CXF-@KZF-@ZXF<br> <br> SELECT @LBXM=@LBXM<br> <br> SELECT @QH=(SELECT TOP 1 QH FROM MWFYYLB WHERE FPHM=@FPHM AND MQLB=@MQLB <br> <br> SELECT @PH=(SELECT TOP 1 PH FROM MWFYYLB WHERE FPHM=@FPHM AND MQLB=@MQLB)<br><br> SELECT @MWBH=(SELECT TOP 1 MWBH FROM MWFYYLB WHERE FPHM=@FPHM AND MQLB=@MQLB)<br><br> SELECT @FPHM=@FPHM<br><br> IF @HJ>0 <br> BEGIN<br><br> INSERT INTO GMSYRBB_RP Values(@I,@RQ,@FPHM,@LBXM,@QH,@PH,@MWBH,@SL,@MK,@CXF,@KZF,@GLWXF,@ZXF,@QTFY,@HJ,@CZYXM)<br> SELECT @I=@I+1<br> END<br><br> ----------------------------------------------- 退墓情况<br><br> SELECT @MK=SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%墓地使用费%' AND FPHM=@FPHM AND TMF=1<br> SELECT @SL=COUNT(DISTINCT MWID) FROM MWFYYLB WHERE XMMC='墓地使用费' AND FPHM=@FPHM AND TMF=1<br> SELECT @CXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC='瓷像费' AND FPHM=@FPHM AND TMF=1<br> SELECT @KZF= SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%刻字费%' AND FPHM=@FPHM AND TMF=1<br> SELECT @ZXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC='装修费' AND FPHM=@FPHM AND TMF=1<br> SELECT @GLWXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%管理费%' AND FPHM=@FPHM AND TMF=1<br> SELECT @HJ=SUM(BCSK) FROM MWFYYLB WHERE FPHM=@FPHM AND TMF=1<br><br> IF @HJ IS NULL SELECT @HJ=0<br> IF @MK IS NULL SELECT @MK=0<br> IF @GLWXF IS NULL SELECT @GLWXF=0<br> IF @CXF IS NULL SELECT @CXF=0<br> IF @KZF IS NULL SELECT @KZF=0<br> IF @ZXF IS NULL SELECT @ZXF=0<br><br> SELECT @QTFY=@HJ-@MK-@GLWXF-@CXF-@KZF-@ZXF<br> <br> SELECT @LBXM=@LBXM<br> <br> SELECT @QH=(SELECT TOP 1 QH FROM MWFYYLB WHERE FPHM=@FPHM AND MQLB=@MQLB <br> <br> SELECT @PH=(SELECT TOP 1 PH FROM MWFYYLB WHERE FPHM=@FPHM AND MQLB=@MQLB)<br><br> SELECT @MWBH=(SELECT TOP 1 MWBH FROM MWFYYLB WHERE FPHM=@FPHM AND MQLB=@MQLB)<br><br> SELECT @FPHM=@FPHM<br><br> IF @SL>0 <br> BEGIN<br> INSERT INTO GMSYRBB_RP Values(@I,@RQ,@FPHM,@LBXM,@QH,@PH,@MWBH,-@SL,-@MK,-@CXF,-@KZF,-@GLWXF,-@ZXF,-@QTFY,-@HJ,@CZYXM)<br> SELECT @I=@I+1<br> END<br> ---------------------------------------------------------------- <br> END<br> ELSE<br> BEGIN<br><br> SELECT @MK=SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%墓地使用费%' AND RQ=@RQ AND FPHM=@FPHM AND LBXM=@LBXM<br> SELECT @SL=COUNT(DISTINCT MWID) FROM MWFYYLB WHERE XMMC='墓地使用费' AND RQ=@RQ AND FPHM=@FPHM AND LBXM=@LBXM AND BCSK>0<br> SELECT @CXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC='瓷像费' AND RQ=@RQ AND FPHM=@FPHM AND LBXM=@LBXM<br> SELECT @KZF= SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%刻字费%' AND RQ=@RQ AND FPHM=@FPHM AND LBXM=@LBXM<br> SELECT @ZXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC='装修费' AND RQ=@RQ AND FPHM=@FPHM AND LBXM=@LBXM<br><br> SELECT @GLWXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%管理费%' AND RQ=@RQ AND FPHM=@FPHM AND LBXM=@LBXM<br><br> SELECT @HJ=SUM(BCSK) FROM MWFYYLB WHERE RQ=@RQ AND FPHM=@FPHM AND LBXM=@LBXM<br> <br> IF @HJ IS NULL SELECT @HJ=0<br> IF @MK IS NULL SELECT @MK=0<br> IF @GLWXF IS NULL SELECT @GLWXF=0<br> IF @CXF IS NULL SELECT @CXF=0<br> IF @KZF IS NULL SELECT @KZF=0<br> IF @ZXF IS NULL SELECT @ZXF=0<br> <br> SELECT @QTFY=@HJ-@MK-@GLWXF-@CXF-@KZF-@ZXF<br> <br> SELECT @LBXM=@LBXM<br> <br> SELECT @QH=(SELECT TOP 1 QH FROM MWFYYLB WHERE FPHM=@FPHM AND LBXM=@LBXM)<br> <br> SELECT @PH=(SELECT TOP 1 PH FROM MWFYYLB WHERE FPHM=@FPHM AND LBXM=@LBXM)<br><br> SELECT @MWBH=(SELECT TOP 1 MWBH FROM MWFYYLB WHERE FPHM=@FPHM AND LBXM=@LBXM)<br><br> SELECT @FPHM=@FPHM<br> IF @HJ>0<br> BEGIN <br> INSERT INTO GMSYRBB_RP Values(@I,@RQ,@FPHM,@LBXM,@QH,@PH,@MWBH,@SL,@MK,@CXF,@KZF,@GLWXF,@ZXF,@QTFY,@HJ,@CZYXM)<br> SELECT @I=@I+1<br> END <br> ---------------------------------------退墓情况<br><br> SELECT @MK=SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%墓地使用费%' AND FPHM=@FPHM AND TMF=1<br> SELECT @SL=COUNT(DISTINCT MWID) FROM MWFYYLB WHERE XMMC='墓地使用费' AND FPHM=@FPHM AND TMF=1<br> SELECT @CXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC='瓷像费' AND FPHM=@FPHM AND TMF=1<br> SELECT @KZF= SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%刻字费%' AND FPHM=@FPHM AND TMF=1<br> SELECT @ZXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC='装修费' AND FPHM=@FPHM AND TMF=1<br><br> SELECT @GLWXF=SUM(BCSK) FROM MWFYYLB WHERE XMMC LIKE '%管理费%' AND FPHM=@FPHM AND TMF=1<br><br> SELECT @HJ=SUM(BCSK) FROM MWFYYLB WHERE FPHM=@FPHM AND TMF=1<br> <br> IF @HJ IS NULL SELECT @HJ=0<br> IF @MK IS NULL SELECT @MK=0<br> IF @GLWXF IS NULL SELECT @GLWXF=0<br> IF @CXF IS NULL SELECT @CXF=0<br> IF @KZF IS NULL SELECT @KZF=0<br> IF @ZXF IS NULL SELECT @ZXF=0<br> <br> SELECT @QTFY=@HJ-@MK-@GLWXF-@CXF-@KZF-@ZXF<br> <br> SELECT @LBXM=@LBXM<br> <br> SELECT @QH=(SELECT TOP 1 QH FROM MWFYYLB WHERE FPHM=@FPHM AND LBXM=@LBXM)<br> <br> SELECT @PH=(SELECT TOP 1 PH FROM MWFYYLB WHERE FPHM=@FPHM AND LBXM=@LBXM)<br><br> SELECT @MWBH=(SELECT TOP 1 MWBH FROM MWFYYLB WHERE FPHM=@FPHM AND LBXM=@LBXM)<br><br> SELECT @FPHM=@FPHM<br><br> IF @SL>0 <br> BEGIN<br> INSERT INTO GMSYRBB_RP Values(@I,@RQ,@FPHM,@LBXM,@QH,@PH,@MWBH,-@SL,-@MK,-@CXF,-@KZF,-@GLWXF,-@ZXF,-@QTFY,-@HJ,@CZYXM)<br> SELECT @I=@I+1<br> END<br> -----------------------------------------<br><br> END<br> FETCH NEXT FROM FP INTO @FPHM<br> END<br> CLOSE FP<br> DEALLOCATE FP<br><br> FETCH NEXT FROM RQ_CUR INTO @RQ<br> END<br> CLOSE RQ_CUR<br> DEALLOCATE RQ_CUR<br><br> INSERT INTO GMSYRBB_RP SELECT @I,NULL,'小 计',NULL,NULL,NULL,NULL,SUM(SL),SUM(MK),SUM(CXF),SUM(KZF),SUM(GLWXF),SUM(ZXF),SUM(QTFY),SUM(HJ),@CZYXM FROM GMSYRBB_RP WHERE LBXM=@LBXM AND CZYXM=@CZYXM<br> SELECT @I=@I+1<br> FETCH NEXT FROM FPSY INTO @LBXM<br>END<br>CLOSE FPSY<br>DEALLOCATE FPSY<br><br>DELETE FROM GMSYRBB_RP WHERE FPHM='小 计' AND LBXM IS NULL AND SL IS NULL<br><br>INSERT INTO GMSYRBB_RP SELECT NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,@CZYXM <br><br>-- SELECT @I=@I+1<br><br>INSERT INTO GMSYRBB_RP SELECT @I,NULL,'合 计',NULL,NULL,NULL,NULL,SUM(SL),SUM(MK),SUM(CXF),SUM(KZF),SUM(GLWXF),SUM(ZXF),SUM(QTFY),SUM(HJ),@CZYXM FROM GMSYRBB_RP WHERE FPHM<>'小 计' AND CZYXM=@CZYXM<br><br>UPDATE GMSYRBB_RP SET SL=NULL WHERE SL=0 AND CZYXM=@CZYXM<br>UPDATE GMSYRBB_RP SET MK=NULL WHERE MK=0 AND CZYXM=@CZYXM<br>UPDATE GMSYRBB_RP SET CXF=NULL WHERE CXF=0 AND CZYXM=@CZYXM<br>UPDATE GMSYRBB_RP SET KZF=NULL WHERE KZF=0 AND CZYXM=@CZYXM<br>UPDATE GMSYRBB_RP SET GLWXF=NULL WHERE GLWXF=0 AND CZYXM=@CZYXM<br>UPDATE GMSYRBB_RP SET ZXF=NULL WHERE ZXF=0 AND CZYXM=@CZYXM<br>UPDATE GMSYRBB_RP SET QTFY=NULL WHERE QTFY=0 AND CZYXM=@CZYXM<br>UPDATE GMSYRBB_RP SET HJ=NULL WHERE HJ=0 AND CZYXM=@CZYXM<br><br>UPDATE GMSYRBB_RP SET GMSYRBB_RP.RQ=MWFYYLB.TMRQ FROM MWFYYLB WHERE GMSYRBB_RP.FPHM=MWFYYLB.FPHM AND GMSYRBB_RP.SL=-1 AND MWFYYLB.TMF=1<br><br>-----------干部存放费<br><br> DECLARE GBCFF CURSOR FOR SELECT RQ,FPHM, JE FROM GBCFFSFDJB WHERE RQ BETWEEN @RQ1 AND @RQ2 ORDER BY FPHM<br><br> OPEN GBCFF<br> FETCH NEXT FROM GBCFF INTO @RQ,@FPHM,@HJ<br> WHILE @@FETCH_STATUS=0<br><br> BEGIN <br> SELECT @I=@I+1<br> INSERT INTO GMSYRBB_RP(CH,RQ,FPHM,LBXM,HJ,CZYXM) Values(@I,@RQ,@FPHM,'干部存放费',@HJ,@CZYXM)<br> FETCH NEXT FROM GBCFF INTO @RQ,@FPHM,@HJ<br> END<br>CLOSE GBCFF<br>DEALLOCATE GBCFF<br><br>INSERT INTO GMSYRBB_RP(CH,CZYXM) VALUES(NULL,@CZYXM)<br><br>SELECT @I=@I+1<br><br>SELECT @HJ=SUM(HJ) FROM GMSYRBB_RP WHERE LBXM='干部存放费' AND CZYXM=@CZYXM<br><br>INSERT INTO GMSYRBB_RP (CH,FPHM,HJ,CZYXM) SELECT @I,'存放费合计' , @HJ,@CZYXM<br><br>INSERT INTO GMSYRBB_RP(CH,CZYXM) VALUES(NULL,@CZYXM)<br><br>SELECT @I=@I+1<br><br>SELECT @HJ=SUM(HJ) FROM GMSYRBB_RP WHERE HJ IS NOT NULL AND CZYXM=@CZYXM AND FPHM NOT LIKE '%计'<br><br>INSERT INTO GMSYRBB_RP(CH,FPHM,HJ,CZYXM) SELECT @I,'总 计',@HJ,@CZYXM<br>GO