不考虑加班,请假,外出之类。
原始记录表:
1:工作日历表calendar
2:排班表worktime
3:人事资料表employee
4:异常类别表(迟到,早退,无刷卡...)abnormity
5:考勤记录表timecard
处理结果表:(可以用表或视图的形式存放)
1:打卡异常 10001 20031102 上午上班 迟到
2:考勤明细表1: 10001 20031101 07:55/12:01/12:02/13:55/18:00/18:01 列出所有打卡明细
3:考勤明细表2: 10001 20031101 07:55 12:01 13:55 18:00
/*工作日历表:
如下假设只有三种工作日历,默认情况如下
1:星期六和星期天不上班
2:星期天不上班
4:每天都上班
*/
createtablecalendar(
datesmalldatetimeprimarykeyclustered,
flag1bit,
flag2bit,
flag3bit
)
execsp_addextendedpropertyN'MS_Description',N'日期',N'user',N'dbo',N'table',N'calendar',N'column',N'date'
execsp_addextendedpropertyN'MS_Description',N'是否上班1',N'user',N'dbo',N'table',N'calendar',N'column',N'flag1'
execsp_addextendedpropertyN'MS_Description',N'是否上班2',N'user',N'dbo',N'table',N'calendar',N'column',N'flag2'
execsp_addextendedpropertyN'MS_Description',N'是否上班3',N'user',N'dbo',N'table',N'calendar',N'column',N'flag3'
/*个别录入资料
insertcalendarselect'20031101',0,1,1
unionallselect'20031102',0,0,1
unionallselect'20031103',1,1,1
unionallselect'20031104',1,1,1
*/
/*********如下存储过程用于批量录入资料**************/
create ProcedureAddWorkCalendar@BDateSmallDateTime,@EDateSmallDateTime
As
Declare@CDateSmallDateTime
Declare@Flag1Bit
Declare@Flag2Bit
Declare@Flag3Bit
Set@CDate=@BDate
IfExists(Select*fromcalendarWherecld_rqBetween@BDateAnd@EDate)
Begin
Raiserror('已有该范围的资料,请核对开始日期和结束日期!!!',16,-1)
Return
End
While@CDate<=@EDate
Begin
Set@Flag1=(CaseWhenDatePart(WeekDay,@CDate)in(1,7)then0Else1End)
Set@Flag2=(CaseWhenDatePart(WeekDay,@CDate)=1then0Else1End)
Set@Flag3=1
InsertcalendarValues(@CDate,@Flag,@Flag1,@Flag2)
Set@CDate=DateAdd(Day,1,@CDate)
End
/******** Usage:
ExecAddWorkCalendar'20031101','20031130'
*********/
/*************
当然,更灵活的方法是如下方式建表:
日期 方式 标志
20011101 1 0
20011101 2 1
20011101 3 1
...
********************/
/*
2:排班表(为简单起见,不考虑加班的排班,且只考虑一天最多需四次刷卡的情况)
*/
createtableworktime(
worktimeidintprimarykeyclustered,
minbchar(5),
minschar(5),
minechar(5),
moutbchar(5),
moutschar(5),
moutechar(5),
ainbchar(5),
ainschar(5),
ainechar(5),
1