|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
限制,如果WHERE子句的查询条件里有不等号(WHEREcoloum!=),MySQL将无法使用索引。类似地,如果WHERE子句的查询条件里使用了函数(WHEREDAY(column)=),MySQL也将无法使用索引。
不思索加班,告假,外出之类。
原始纪录表:
1:事情日历表calendar
2:排班表worktime
3:人事材料表employee
4:非常种别表(早退,迟到,无刷卡...)abnormity
5:考勤纪录表timecard
处置了局表:(能够用表或视图的情势寄存)
1:打卡非常1000120031102上午下班早退
2:考勤明细表1:100012003110107:55/12:01/12:02/13:55/18:00/18:01列出一切打卡明细
3:考勤明细表2:100012003110107:5512:0113:5518:00
/*事情日历表:
以下假定只要三种事情日历,默许情形以下
1:礼拜六和礼拜天不下班
2:礼拜天不下班
4:天天都下班
*/
createtablecalendar(
datesmalldatetimeprimarykeyclustered,
flag1bit,
flag2bit,
flag3bit
)
execsp_addextendedpropertyNMS_Description,N日期,Nuser,Ndbo,Ntable,Ncalendar,Ncolumn,Ndate
execsp_addextendedpropertyNMS_Description,N是不是下班1,Nuser,Ndbo,Ntable,Ncalendar,Ncolumn,Nflag1
execsp_addextendedpropertyNMS_Description,N是不是下班2,Nuser,Ndbo,Ntable,Ncalendar,Ncolumn,Nflag2
execsp_addextendedpropertyNMS_Description,N是不是下班3,Nuser,Ndbo,Ntable,Ncalendar,Ncolumn,Nflag3
/*一般录进材料
insertcalendarselect20031101,0,1,1
unionallselect20031102,0,0,1
unionallselect20031103,1,1,1
unionallselect20031104,1,1,1
*/
/*********以下存储历程用于批量录进材料**************/
createProcedureAddWorkCalendar@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:
ExecAddWorkCalendar20031101,20031130
*********/
/*************
固然,更天真的办法是以下体例建表:
日期 体例 标记
2001110110
2001110121
2001110131
...
********************/
/*
2:排班表(为复杂起见,不思索加班的排班,且只思索一天最多需四次刷卡的情形)
*/
createtableworktime(
worktimeidintprimarykeyclustered,
minbchar(5),
minschar(5),
minechar(5),
moutbchar(5),
moutschar(5),
moutechar(5),
ainbchar(5),
ainschar(5),
ainechar(5),
aoutbchar(5),
aoutschar(5),
aoutechar(5)
)
go
execsp_addextendedpropertyNMS_Description,N班制编号,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Nworktimeid
execsp_addextendedpropertyNMS_Description,N上午下班始,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Nminb
execsp_addextendedpropertyNMS_Description,N上午下班尺度,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Nmins
execsp_addextendedpropertyNMS_Description,N上午下班止,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Nmine
execsp_addextendedpropertyNMS_Description,N上午上班始,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Nmoutb
execsp_addextendedpropertyNMS_Description,N上午上班尺度,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Nmouts
execsp_addextendedpropertyNMS_Description,N上午上班止,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Nmoute
execsp_addextendedpropertyNMS_Description,N下战书下班始,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Nainb
execsp_addextendedpropertyNMS_Description,N下战书下班尺度,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Nains
execsp_addextendedpropertyNMS_Description,N下战书下班止,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Naine
execsp_addextendedpropertyNMS_Description,N下战书上班始,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Naoutb
execsp_addextendedpropertyNMS_Description,N下战书上班尺度,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Naouts
execsp_addextendedpropertyNMS_Description,N下战书上班止,Nuser,Ndbo,Ntable,Nworktime,Ncolumn,Naoute
/*
注:在下班始-下班尺度间打卡属于一般打卡,在下班尺度-下班止间打卡属于早退
鄙人班始-上班尺度间打卡属于迟到,鄙人班尺度-上班止间打卡属于一般打卡
其他工夫打卡属于有效打卡。
*/
--3:人事材料表(只列出与考勤有关的字段)
createtableemployee(
worknochar(6)primarykey,
[name]varchar(10),
calendarFlagintcheck(calendarFlagin(1,2,3)),--1,2,3分离暗示事情日历中的标记1,标记2,标记3
worktimeidint--排班表中的班制
)
go
execsp_addextendedpropertyNMS_Description,N工号,Nuser,Ndbo,Ntable,Nemployee,Ncolumn,Nworkno
execsp_addextendedpropertyNMS_Description,N姓名,Nuser,Ndbo,Ntable,Nemployee,Ncolumn,Nname
execsp_addextendedpropertyNMS_Description,N事情日历体例,Nuser,Ndbo,Ntable,Nemployee,Ncolumn,NcalendarFlag
execsp_addextendedpropertyNMS_Description,N班制,Nuser,Ndbo,Ntable,Nemployee,Ncolumn,Nworktimeid
/*
calendarFlag1,2,3分离暗示事情日历中的标记1,标记2,标记3
worktimeid对应排班表中的班制
*/
--4:非常种别表abnormity
createtableabnormity(
abnormitynointprimarykeyclustered,
[description]varchar(10)
)
go
execsp_addextendedpropertyNMS_Description,N非常种别,Nuser,Ndbo,Ntable,Nabnormity,Ncolumn,Nabnormityno
execsp_addextendedpropertyNMS_Description,N非常申明,Nuser,Ndbo,Ntable,Nabnormity,Ncolumn,Ndescription
/**************
非常包含:早退(还可细分红早退的工夫段),迟到,无刷卡...
固然大概另有扣薪体例之类的,此处不予思索。
*****************/
5:考勤纪录表timecard
createtabletimecard(
worknochar(6),
[date]datetime,
constraint[pk_timecard]primarykeyclustered
(
workno,
[date]
)ON[PRIMARY]
)
go
execsp_addextendedpropertyNMS_Description,N工号,Nuser,Ndbo,Ntable,Ntimecard,Ncolumn,Nworkno
execsp_addextendedpropertyNMS_Description,N打卡工夫,Nuser,Ndbo,Ntable,Ntimecard,Ncolumn,Ndate
/*******
实在我实践中是按卡号(对应工号),日期,工夫,卡钟号 四个字段来存的。
*******/
/****************以下处置失掉 考勤明细表1:**********/
--1.创立一个兼并的函数
createfunctionf_kqlist(@worknochar(6),@datechar(8))
returnsvarchar(400)
as
begin
declare@strvarchar(1000)
set@str=
select@str=@str+/+convert(char(8),[date],108)fromtimecard
whereworkno=@worknoanddatediff(day,[date],@date)=0
set@str=right(@str,len(@str)-1)
return(@str)
End
/*Usage:
selectdistinctworkno,date,dbo.f_kqlist(workno,[date])
fromtimecard
whereworkno=102337andconvert(char(8),[date],112)=20030814
*/
剩下的留给人人吧。实在也不难,就看谁的效力对照高一些而已。:D
(我的做法: 非常处置:用存储历程,用游标做的,懒得往优化了
考勤明细表2: 用函数,本来用游标,欠好,厥后才改用函数的)
但我们知道,若使用statement,并没有上述需要的数据。试想binlog中记录了一句updatetsetf1=3whereid=3。怎么恢复呢? |
|