存储过程很慢单独执行很快_SQL 存储过程施行很慢,但是复制出来单独执行很快!为什么呢(2)...

当前位置:我的异常网» 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

文章评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值