本人现在正在做一个考勤系统.现在遇到了一个难道.请各位大师.给予支持
现在我要统计出勤表中每人的缺勤的时间与天数.表结构如下:
ID 员工ID 打卡时间
1 001 2007-01-01 07:07:45
2 001 2007-01-02 07:07:45
3 001 2007-01-03 07:07:45
4 002 2007-01-01 07:07:45
5 002 2007-01-03 07:07:45
6 003 2007-01-02 07:07:45
想得到结果如下:
员工ID 缺勤日期
001 2007-01-04 至 2007-01-31
002 除 1 2 号外的所有日期
003 除 2 号外的所有日期就是怎么样统计每个人具体的缺勤日期各位大师.在回帖时.帮我考虑一下怎么样统计当月/每个月的缺勤天数
现在我要统计出勤表中每人的缺勤的时间与天数.表结构如下:
ID 员工ID 打卡时间
1 001 2007-01-01 07:07:45
2 001 2007-01-02 07:07:45
3 001 2007-01-03 07:07:45
4 002 2007-01-01 07:07:45
5 002 2007-01-03 07:07:45
6 003 2007-01-02 07:07:45
想得到结果如下:
员工ID 缺勤日期
001 2007-01-04 至 2007-01-31
002 除 1 2 号外的所有日期
003 除 2 号外的所有日期就是怎么样统计每个人具体的缺勤日期各位大师.在回帖时.帮我考虑一下怎么样统计当月/每个月的缺勤天数
(
cardid varchar(10),
ddate datetime
)
insert into #kk select '001','2007-01-01 07:07:45.000'
insert into #kk select '001','2007-01-02 07:07:45.000'
insert into #kk select '001','2007-01-03 07:07:45.000'
insert into #kk select '002','2007-01-01 07:07:45.000'
insert into #kk select '002','2007-01-03 07:07:45.000'
insert into #kk select '003','2007-01-02 07:07:45.000'create table #aa
(
id int identity,
cardid varchar(10),
ddate varchar(10)
)--drop table #aa
--drop table #kk
select * from #aa
select * from #kkinsert into #aa select cardid,convert(varchar(10),ddate,120)as a
from #kk
create table #month
(
dday varchar(10)
)
declare @month as CHAR(2)
declare @year as CHAR(4)
declare @Minday as datetime
declare @Maxday as datetime
set @year='2007'
set @month='01'
SET @Minday =@year+'-'+@month+'-01'
select @Maxday=dateadd(m,1,@minday )while datediff(d,@Minday,@Maxday)>0
begin
insert into #month select convert(varchar(10),@Minday,120)
select @Minday=dateadd(d,1,@Minday)
end
select * from #month--delete #month
select * from #month a
left join #aa b
on a.dday=b.ddate and cardid='001'
--where cardid='001'null 值记录的就是