统计所有员工节假日加班时间

fuxiaocaolove 2012-12-26 03:27:06
按月份统计节假日和周末加班
方法:sum(每个员工实际提交的工时—理论工时)


这是自己写的查询按月查询每个员工实际工时的语句
select


sr.id,
sr.full_name,
sum(PE.PRACTSUM/3600/8) act_days,-------实际工时
month(PP.PRSTART) start

FROM
srm_resources sr
inner join PRTIMESHEET pt on sr.id = pt.prresourceid
inner join PRTIMEPERIOD PP on Pt.PRTIMEPERIODID = PP.PRID
inner join pac_mnt_resources pmr on sr.unique_name = pmr.RESOURCE_CODE
inner join prtimeentry pe on pt.prid = pe.prtimesheetid
inner join prtypecode ptc on pe.prtypecodeid = ptc.prid

where
pp.prstart >= '2012-01-01'
and pp.prfinish <= '2013-01-01'
and pt.prstatus = 4
and (pmr.LOCATIONID = 'C1_BJ' or pmr.LOCATIONID = 'C1_sh')
and ptc.prid <>5000007
group by sr.id,sr.full_name,month(pp.prstart)




然后新建了一个日历表Corporate_Calendar标记所有的假期(holiday)和工作日(workday),用于统计每个月的工作日和节假日

例如1月份
实际工时的计算:先统计每个员工的工时,再将同一月份的工时汇总


理论工时的计算:分3种情况
1. 正常情况:员工的date_of_hire(入职日期)<2012-01-01 and date_of_termination(离职日期) = null or date_of_termination >2012-01-31,理论工时的计算: select count(*) days from Corporate_Calendar where holiday = 0 and month(date) = 1
2. 1月份入职:date_of_hire(入职日期)>2012-01-01, 理论工时的计算:select count(*) days from Corporate_Calendar where holiday = 0 and date between date_of_hire and 该月最后一天
3. 3.1月份离职:date_of_termination <2012-01-31, 理论工时的计算:select count(*) days from Corporate_Calendar where holiday = 0 and date between 该月第一天 and date_of_termination

有没有人告诉我大概怎么写sql或者存储过程,思路明白,不知道怎么下手
...全文
200 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
superdeng201 2012-12-26
  • 打赏
  • 举报
回复
妹子,要实现的功能太完美了,不可能完成。我公司现在用那套考勤系统实现你多说的80%

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧