代码:
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
ALTER procedure dbo.Pro_考勤月统计
--参数
@机构 varchar(20) = '南宁所',
@部门 varchar(20) = '审计部',
@年份 char(4)='2004',
@月份 varchar(2) ='1'
as
select 机构,部门,姓名,
在所坐班 =convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='1')),
本市进点 =convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='2')),
出差 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='3')),
病假 =convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='4')),
事假 =convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='5')),
年休假 =convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='6')),
产假 =convert(decimal(4,1),( select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='7')),
哺乳假 =convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='8')),
婚假 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='9')),
丧假 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='10')),
探亲假 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='11')),
旅游假 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='12')),
旷工 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='13')),
迟到 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='14')),
早退 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 ='15')),
总出勤 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 between '1' and '3' )),
各种假期 = convert(decimal(4,1),(select count(*)/2.0 from vw_所有考勤表 where 姓名 = a.姓名 and month(日期) = @月份 and year(日期)=@年份 and 类型 between '4' and '15' ))
from worker as a
where 机构=@机构 and 部门=@部门
order by 机构,部门,姓名
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO