
1 CREATE PROCEDURE [dbo].[Proc_PX_Situation] 2 @BMDateFrom nvarchar(50), --報名時間 從 3 @BMDateEnd nvarchar(50), --報名時間 到 4 @BenlonFenJu nvarchar(50) --所屬分局 5 AS 6 begin 7 --declare @SqlStr nvarchar(2000); 8 create table #temp_table( 9 Row_ID int, 10 RowGuid varchar(50), --計划Guid 11 --PX_Plan 12 PlanName nvarchar(100), --培訓名稱 13 UnitCount int, --計划參加企業總數 14 UserCount int, --計划參加人員總數 15 --PX_BaoM 16 BMUnitCount int, --實際報名企業總數 某一個計划下面報名的 DanWeiName的數量,不重復 17 BMUserCount int, --實際報名人員總數 某一個計划下面報名的 Count(UserGuid) 18 PayUnitCount int, --實際交費企業總數 19 PayUserCount int, --實際交費人員總數 20 PXUnitCount int, --實際培訓企業總數 21 PXUserCountt int , --實際培訓人員總數 22 BaoMDNum nvarchar(50) --報名點 23 -- BaoMdate datetime --報名時間 24 ) 25 26 insert into #temp_table( 27 Row_ID, 28 RowGuid , --計划Guid 29 --PX_Plan 30 PlanName , --培訓名稱 31 UnitCount , --計划參加企業總數 32 UserCount , --計划參加人員總數 33 --PX_BaoM 34 BMUnitCount , --實際報名企業總數 某一個計划下面報名的 DanWeiName的數量,不重復 35 BMUserCount , --實際報名人員總數 某一個計划下面報名的 Count(UserGuid) 36 PayUnitCount , --實際交費企業總數 37 PayUserCount , --實際交費人員總數 38 PXUnitCount , --實際培訓企業總數 39 PXUserCountt , --實際培訓人員總數 40 BaoMDNum --報名點 41 -- BaoMdate --報名時間 42 ) 43 (select Row_ID, RowGuid,PlanName,'','','','','','','','','' from PX_Plan) 44 45 --統計start 46 47 --計划參加企業總數 48 if @BenlonFenJu='' 49 update a set a.UnitCount=b.UnitCount from #temp_table a, 50 ( 51 select RowGuid,UnitCount from px_plan 52 )b where a.RowGuid=b.RowGuid 53 else 54 update a set a.UnitCount=b.UnitCount from #temp_table a, 55 ( 56 select PlanGuid,UnitCount,BaoMDCode from PX_PlanBaoMD where BaoMDCode=@BenlonFenJu 57 )b where a.RowGuid=b.PlanGuid 58 59 --計划參加人員總數 60 if @BenlonFenJu='' 61 update a set a.UserCount=b.UserCount from #temp_table a, 62 ( 63 select RowGuid,UserCount from px_plan 64 )b where a.RowGuid=b.RowGuid 65 else 66 update a set a.UserCount=b.UserCount from #temp_table a, 67 ( 68 select PlanGuid,UserCount,BaoMDCode from PX_PlanBaoMD where BaoMDCode=@BenlonFenJu 69 )b where a.RowGuid=b.PlanGuid 70 71 --實際報名企業總數 72 update a set a.BMUnitCount=b.total from #temp_table a, 73 ( 74 select planguid, count(distinct DanWeiGuid) total from ( 75 select BMAddDate,planguid,DanWeiGuid from View_PX_Plan_BaoM 76 where BMAddDate >(case @BMDateFrom when '' then '1900-01-01' else @BMDateFrom end) 77 and BMAddDate<(case @BMDateEnd when '' then GETDATE() else @BMDateEnd end) 78 and BaoMDNum in (select BaoMDCode from PX_PlanBaoMD where BaoMDCode like '%'+@BenlonFenJu+'%') 79 )p group by p.planguid 80 )b where a.RowGuid=b.PlanGuid 81 82 --實際報名人員總數 83 update a set a.BMUserCount=b.total from #temp_table a, 84 ( 85 select planguid,count(UserGuid) total from ( 86 select BMAddDate,planguid,UserGuid from View_PX_Plan_BaoM 87 where BMAddDate >(case @BMDateFrom when '' then '1900-01-01' else @BMDateFrom end) 88 and BMAddDate<(case @BMDateEnd when '' then GETDATE() else @BMDateEnd end) 89 and BaoMDNum in (select BaoMDCode from PX_PlanBaoMD where BaoMDCode like '%'+@BenlonFenJu+'%') 90 )p group by p.planguid 91 )b where a.RowGuid=b.PlanGuid 92 93 --實際交費企業總數 94 update a set a.PayUnitCount=b.total from #temp_table a, 95 (select planguid,count(distinct DanWeiGuid) total from( 96 select BMAddDate,planguid,DanWeiGuid from View_PX_Plan_BaoM 97 where IsPay=1 98 and BMAddDate >(case @BMDateFrom when '' then '1900-01-01' else @BMDateFrom end) 99 and BMAddDate<(case @BMDateEnd when '' then GETDATE() else @BMDateEnd end) 100 and BaoMDNum in (select BaoMDCode from PX_PlanBaoMD where BaoMDCode like '%'+@BenlonFenJu+'%') 101 )p group by p.planguid 102 )b where a.RowGuid=b.PlanGuid 103 104 --實際交費人員總數 105 update a set a.PayUserCount=b.total from #temp_table a, 106 (select planguid,count(UserGuid) total from( 107 select BMAddDate,planguid,UserGuid from View_PX_Plan_BaoM 108 where IsPay=1 109 and BMAddDate >(case @BMDateFrom when '' then '1900-01-01' else @BMDateFrom end) 110 and BMAddDate<(case @BMDateEnd when '' then GETDATE() else @BMDateEnd end) 111 and BaoMDNum in (select BaoMDCode from PX_PlanBaoMD where BaoMDCode like '%'+@BenlonFenJu+'%') 112 )p group by p.planguid 113 )b where a.RowGuid=b.PlanGuid 114 115 --實際培訓企業總數 116 update a set a.PXUnitCount=b.total from #temp_table a, 117 (select planguid,count(distinct DanWeiGuid) total from( 118 select BMAddDate,planguid,DanWeiGuid from View_PX_Plan_BaoM 119 where IsPay=1 and IsPeiXun=1 120 and BMAddDate >(case @BMDateFrom when '' then '1900-01-01' else @BMDateFrom end) 121 and BMAddDate<(case @BMDateEnd when '' then GETDATE() else @BMDateEnd end) 122 and BaoMDNum in (select BaoMDCode from PX_PlanBaoMD where BaoMDCode like '%'+@BenlonFenJu+'%') 123 )p group by p.planguid 124 )b where a.RowGuid=b.PlanGuid 125 126 --實際培訓人員總數 127 update a set a.PXUserCountt=b.total from #temp_table a, 128 (select planguid,count(UserGuid) total from( 129 select BMAddDate,planguid,UserGuid from View_PX_Plan_BaoM 130 where IsPay=1 and IsPeiXun=1 131 and BMAddDate >(case @BMDateFrom when '' then '1900-01-01' else @BMDateFrom end) 132 and BMAddDate<(case @BMDateEnd when '' then GETDATE() else @BMDateEnd end) 133 and BaoMDNum in (select BaoMDCode from PX_PlanBaoMD where BaoMDCode like '%'+@BenlonFenJu+'%') 134 )p group by p.planguid 135 )b where a.RowGuid=b.PlanGuid 136 137 --報名點 138 update a set a.BaoMDNum=b.BaoMDNum from #temp_table a, 139 (select distinct planguid,BaoMDNum from View_PX_Plan_BaoM)b where a.RowGuid=b.PlanGuid 140 141 142 --報名時間 --AddDate 143 --update a set a.BaoMdate=b.BMAddDate from #temp_table a, 144 --(select planguid,DanWeiGuid, BMAddDate from View_PX_Plan_BaoM)b where a.RowGuid=b.PlanGuid 145 --統計end 146 147 select * from #temp_table order by Row_ID DESC 148 149 end 150 151 152 153 154 155 156 GO