当前位置:我的异常网» Sql Server » SQL 存储过程施行很慢,但是复制出来单独执行很快!
SQL 存储过程施行很慢,但是复制出来单独执行很快!为什么呢(2)
www.myexceptions.net 网友分享于:2013-12-17 浏览:479次
) A where A.YYYYMM=YYMonthHL.YM and A.A0188=YYMonthHL.A0188 and A.YYYYMM=@YM
and YYMonthHL.A0188 in (select A0188 from A01 where A01KQKS in (@KQKS))
--计算本月工作
update YYMonthHL set BYGZ=A.GZ
from
(select A0188,YYYYMM,SUM(GZ) as GZ from (
select A0188,CONVERT(varchar(6), KQDate, 112) AS YYYYMM,round(cast(COUNT(KQ) as numeric(10,2))/2,2) as GZ
from ZSYY_KQ_HZ
where KQ in(select ID from YyZD where GZ=1 )
group by (A0188),CONVERT(varchar(6), KQDate, 112)
) kk group by A0188,YYYYMM)A where A.YYYYMM=YYMonthHL.YM and A.A0188=YYMonthHL.A0188 and A.YYYYMM=@YM
and YYMonthHL.A0188 in (select A0188 from A01 where A01KQKS in (@KQKS))
--计算夜班次数
update YYMonthHL set BYYB=A.JYB
from
(select A0188,CONVERT(varchar(6), KQDate, 112) AS YYYYMM, round(cast(COUNT(KQ) as numeric(10,2)),2) as JYB from ZSYY_KQ_HZ
where KQ in(select ID from YyZD where JYB=1 ) and Type='NT'
group by (A0188),CONVERT(varchar(6), KQDate, 112))A
where A.YYYYMM=YYMonthHL.YM and A.A0188=YYMonthHL.A0188 and A.YYYYMM=@YM
and YYMonthHL.A0188 in (select A0188 from A01 where A01KQKS in (@KQKS))
--补假天数
----PS:先计算上班天数大于模板中的上班天数,例如周六日勾选出勤累计积假。
update YYMonthHL set BYBJ=case when (isnull(BYGZ,0)-round(cast(A.HZ as numeric(10,2))/2,2))<0 then 0
else isnull(BYGZ,0)-round(cast(A.HZ as numeric(10,2))/2,2) end
from (select
SUM( case when [am] in (64) then 1 else 0 end)+
SUM( case when [pm] in (64) then 1 else 0 end)+
SUM( case when [nt] in (64) then 1 else 0 end)+
0 as HZ,@YM YM from YYMB
where month=SUBSTRING(@YM,0,5)+'-'+SUBSTRING(@YM,5,7) and mode=1 group by month ) A
where A.YM=YYMonthHL.YM and A.YM=@YM
and YYMonthHL.A0188 in (select A0188 from A01 where A01KQKS in (@KQKS))
----PS:加上本月正补假天数
update YYMonthHL set BYBJ=BYBJ+A.ZBXTS
from (
select KK.A0188,kk.YYYYMM,SUM(kk.ZBXTS) as ZBXTS from (
select A0188,CONVERT(varchar(6), KQDate, 112) AS YYYYMM,
sum(BXTS) as ZBXTS from ZSYY_KQ_HZ,YyZD
where BXTS>0 and ZSYY_KQ_HZ.KQ=YyZD.ID
group by (A0188),CONVERT(varchar(6), KQDate, 112)
UNION ALL
select A0188,CONVERT(varchar(6), KQDate, 112) AS YYYYMM,
count(A0188)*1 as ZBXTS from ZSYY_KQ_HZ
where Type='NT' and KQ='64' group by (A0188),CONVERT(varchar(6), KQDate, 112)
) KK group by A0188,YYYYMM) A
where A.YYYYMM=YYMonthHL.YM and A.A0188=YYMonthHL.A0188 and A.YYYYMM=@YM
and YYMonthHL.A0188 in (select A0188 from A01 where A01KQKS in (@KQKS))
--本月积假天数
----本月补假天数
update YYMonthHL set JJTS=BYBJ where YM=@YM
文章评论