300分 根据打卡记录自动识别是属于哪个班次,来者人人有分
fa_ge 2008-05-20 12:00:03 --员工表
create table #employee
(id int identity(1,1),gh varchar(10),dept_no varchar(10),name varchar(10))
insert into #employee
select '10001','001','张无忌' union all
select '10002','001','张三丰' union all
select '10003','002','韦小宝' union all
select '10004','002','成近南' union all
select '10005','003','和申'
--部门表
create table #dept
(id int identity(1,1),dept_no varchar(10),dept_name varchar(10))
insert into #dept
select '001','IT部' union all
select '002','产品部' union all
select '003','制造部'
--考勤表
create table #check_work
(id int identity(1,1),person_number varchar(10),type varchar(10),
begindate datetime, --开始考勤时间
enddate datetime --结束考勤时间
)
-- case when type=员工 then person_number=员工编号
-- when type=部门 then person_number=部门编号
insert into #check_work
select '001','部门','2008-05-05 00:00:00','2008-05-09 00:00:00' union all
select '1003','员工','2008-05-05 00:00:00','2008-05-09 00:00:00' union all
select '1004','员工','2008-05-05 00:00:00','2008-05-09 00:00:00' union all
select '1005','员工','2008-05-05 00:00:00','2008-05-09 00:00:00'
--班次表
create table #workset(id int identity(1,1),
workset_number varchar(10), --班次编号
workset_name varchar(20), --班次名称
begindate varchar(5),enddate varchar(5), --上班时间,下班时间
begindate1 varchar(5),enddate1 varchar(5) , --上班打卡起始时间和上班打卡结束时间
begindate2 varchar(5),enddate2 varchar(5), --下班打卡起始时间和下班打卡结束时间
rest_begin1 varchar(5),rest_end1 varchar(5) --中间休息起始时间和结束时间 ,在这里暂不考虑
)
insert into #workset
select '01','管理干部','09:00','18:00','06:00','09:00','18:00','23:59','12:00','13:00' union all --干部班次一天只打两次卡
select '02','员工正常班次一','08:00','11:30','07:00','08:00','11:30','12:00','','' union all --这个班次没有休息时间
select '03','员工正常班次二','13:00','17:30','12:00','13:00','17:30','17:59','','' union all --这个班次没有休息时间
select '04','冲压车间夜班班次','20:00','04:30','19:30','20:00','04:30','05:00','23:00','00:00'
--打卡记录表
create table #ropen
(id int identity(1,1),
gh varchar(10), --员工工号
open_time datetime --打卡时间
)
insert into #ropen
select '10001','2008-05-05 08:54:00.000' union all --从这开始部门为IT部,属干部班次 09:00-18:00
select '10001','2008-05-05 08:58:00.000' union all
select '10001','2008-05-05 18:04:00.000' union all
select '10002','' union all --10002 上午没打上卡
select '10002','2008-05-05 18:15:00.000' union all
select '10002','2008-05-05 18:20:00.000' union all
select '10003','2008-05-05 07:54:00.000' union all --从这开始是员工班次, 08:00-11:30,13:00=17:30
select '10003','2008-05-05 11:40:00.000' union all
select '10003','2008-05-05 12:54:00.000' union all --10003 第二个正常班次打卡记录
select '10003','2008-05-05 17:30:00.000' union all
select '10003','2008-05-05 17:54:00.000' union all
select '10004','2008-05-05 07:58:00.000' union all
select '10004','' union all --10004第一个班次下班没有打上卡
select '10004','2008-05-05 12:54:00.000' union all
select '10004','2008-05-05 17:54:00.000' union all
select '10005','2008-05-05 19:58:00.000' union all --从这开是夜班 20:00-04:30
select '10005','2008-05-06 04:51:00.000'
--drop table #employee,#dept,#check_work,#workset,#ropen
根据#check_work表中排了考勤的员工的打卡记录自动
得到 10001,10002是属于'01'班次
10003,10004是属于 '02','03'班次
10005 是属于'04'班次
第一次弄考勤,任务崔得太急了。c友们帮我看看,提提建义也好。
来者都是客,人人有分。