① sql 考勤数据 未打卡的日期问题
第一个是sqlserver的,第二个是oracle的,我这里建的t5是因为没有完整的表记录,取不到完整的时间,而你这里的表有完整的记录,所以select distinct substring(start_time,0,11) dt,plan_id,cardno from t5这句完全可以select distinct substring(start_time,0,11) dt,plan_id,cardno from tabname(tabname就是你上面那张表)来替代t5,这样可以取出完整的时间集合,总不会出现所有人上班时间都没来吧,呵呵。
createtablet5
(start_timevarchar(20),plan_idvarchar(1),cardNovarchar(10));
createtablet4
(
attend_idvarchar(4),plan_idvarchar(1),cardNovarchar(10),start_timevarchar(20),end_timevarchar(20)
);
insertintot4
select'4613','5','00009','2012-09-1108:37',null
unionall
select'4614','5','00009','2012-09-1308:53','2012-09-1318:01'
unionall
select'4615','5','00009','2012-09-1508:54','2012-09-1518:02'
unionall
select'4616','5','00009','2012-09-1708:30','2012-09-1718:03'
unionall
select'4617','5','00009','2012-09-1808:37','2012-09-1819:45'
unionall
select'4618','5','00009','2012-09-1908:37','2012-09-1919:01'
unionall
select'4619','5','00009','2012-09-2008:37','2012-09-2018:45'
unionall
select'4620','5','00009','2012-09-2108:37',null
unionall
select'4621','5','00009','2012-09-2308:37','2012-09-2318:35';
insertintot5
select'2012-09-1108:37','5','00009'
unionall
select'2012-09-1208:37','5','00009'
unionall
select'2012-09-1308:37','5','00009'
unionall
select'2012-09-1408:37','5','00009'
unionall
select'2012-09-1508:37','5','00009'
unionall
select'2012-09-1508:37','5','00009'
unionall
select'2012-09-1608:37','5','00009'
unionall
select'2012-09-1708:37','5','00009'
unionall
select'2012-09-1808:37','5','00009'
unionall
select'2012-09-1808:37','5','00009'
unionall
select'2012-09-2008:37','5','00009'
unionall
select'2012-09-2108:37','5','00009'
unionall
select'2012-09-2208:37','5','00009'
unionall
select'2012-09-2308:37','5','00009'
unionall
select'2012-09-2408:37','5','00009';
--sqlserver语句
selectt4.attend_id,
t1.plan_id,
t1.cardno,
casewhensubstring(t4.start_time,0,11)=t1.dtthent4.start_timeelset1.dt+'00:00'endstart_time,
casewhensubstring(t4.end_time,0,11)=t1.dtthent4.end_timeelset1.dt+'00:00'endend_time
from
(selectdistinctsubstring(start_time,0,11)dt,plan_id,cardnofromt5)t1
leftjoint4ont1.dt=substring(t4.start_time,0,11)andt1.cardno=t4.cardno
orderbyt1.dt;
--oracle
selectt4.attend_id,
t1.plan_id,
t1.cardno,
casewhensubstr(t4.start_time,0,10)=t1.dtthent4.start_timeelset1.dt||'00:00'endstart_time,
casewhensubstr(t4.end_time,0,10)=t1.dtthent4.end_timeelset1.dt||'00:00'endend_time
from
(selectdistinctsubstr(start_time,0,10)dt,plan_id,cardnofromt5)t1
leftjoint4ont1.dt=substr(t4.start_time,0,10)andt1.cardno=t4.cardno
orderbyt1.dt;
结果:
4613 5 00009 2012-09-1108:37 2012-09-1100:00
NULL 5 00009 2012-09-1200:00 2012-09-1200:00
4614 5 00009 2012-09-1308:53 2012-09-1318:01
NULL 5 00009 2012-09-1400:00 2012-09-1400:00
4615 5 00009 2012-09-1508:54 2012-09-1518:02
NULL 5 00009 2012-09-1600:00 2012-09-1600:00
4616 5 00009 2012-09-1708:30 2012-09-1718:03
4617 5 00009 2012-09-1808:37 2012-09-1819:45
4619 5 00009 2012-09-2008:37 2012-09-2018:45
4620 5 00009 2012-09-2108:37 2012-09-2100:00
NULL 5 00009 2012-09-2200:00 2012-09-2200:00
4621 5 00009 2012-09-2308:37 2012-09-2318:35
NULL 5 00009 2012-09-2400:00 2012-09-2400:00
有问题再追问吧,望采纳。
② 用SQLserver获取考勤打卡缺失的记录
select * from 打卡记录 where 最早打卡时间 is null or 最晚打卡时间 is null
③ 如何实现SQLServer与舒特考勤系统相连接
没用过这个考勤系统
④ sqlserver考勤月度汇总sql怎么写
你这个表,明显是新系统。而且没有考勤开发经验的。
考勤类型只分ONty和OFFty,但实际上需求4总打卡次数。。。。
而且要写到跟你图二一样,还差一张排班表。。。。。
建议你这样,先用工号、日期、ID顺序归档一次,根据班次区间先分布没次打卡树叶上午还是下午,否则现在的逻辑,忘打卡一次就会导致考勤数据异常的。
⑤ 将sqlserver一张实时考勤表变成带按月统计的(例如10月 有31天就是31个字段 ) 根据时间分为上下午
这个根本用不着存储过程。。发QQ给我吧。
⑥ sqlserver 查询记录根据人员考勤记录去重,当时只去重当天的,不同日期的可以重复,sql怎么写 求助
用分析函数row_number() over (partition by ... order by ...)给记录进行分组编号,按人员id和考勤日期进行分组(如果考勤日期带时分秒,需先截断到日),按时间升序排序;这样,就得到人员ID在同一考勤日期下的编号值(编号值是从1开始的),然后,只取编号值为1的记录。
SQL类似:
selects.id,s.name,s.date,s.card_time
from(
selectd.id,d.name,d.date,d.card_time,
row_number()over(partitionbyd.id,d.dateorderbyd.card_time)asrow_idx
fromdata_tabled
)s
wheres.row_idx=1
⑦ 求助数据库大神,公司的考勤系统出问题,SQLserver里面的数据库成了灰色,连接不上,库里也成了空的。
sql server 2008 数据库附加后变成只读的灰色, 解决办法: 点击数据库选属性----在选项中----状态,在数据为只读处选FALSE点确定即可 在之后如果报错,空间与内存不足等情况下,找到相应的数据文件与日志文件选择安全添加network services 添加进去并点修改权限。
⑧ 用 sqlserver 怎样查询出 数据表里 某月上班连续打卡15天的人
这个功能数据库用SQL语句是实现不了的,建议把每个月的上班情况读出来,用编程语言通过编程判断。你的需求是属于业务逻辑功能,数据库实现不了这么复杂的功能。
⑨ 考勤机如何连接sqlsever2000数据库
目前市场上很多考勤机配套考勤软件都是用ACCESS数据库,专业版的考勤系统软件一般都是用SQL数据库,连接sqlserver2000数据库其实也很简单,以下以全易通考勤软件连接sqlserver2000数据库作为实例进行说明。
1、先安装好sqlserver2000数据库,安装好后,启动一下SQL服务器
2、再安装好考勤软件,找到考勤软件"创建或连接数据库“菜单,再点创建数据库,这时考勤软件就会提示:操作成功!
3、如果考勤软件提示:SQL2000不存在或拒绝访问,这说明SQL200数据库没有安装好,或SQL服务器没有启动。
⑩ sql 行转列,如图所示是每个人每天的考勤打卡数据,怎样可以把每个人的刷卡时间横着显示
如果是sqlserver你需要先建立一个函数像这样
CREATEFUNCTION[dbo].[JoinString]
(
@timevarchar(100),
@namevarchar(100)
)
RETURNSvarchar(2000)
AS
BEGIN
DECLARE@tmpvarchar(1000)
set@tmp=''
SELECT@tmp=@tmp+','+sjfrom(
select人员姓名,CONVERT(varchar(100),刷卡日期时间,23)asrq,
CONVERT(varchar(100),刷卡日期时间,24)assj
from你的表名
)t
where人员姓名=@nameandrq=@time
RETURN@tmp
END
然后就可以调用了,如下
select人员姓名,rq,dbo.JoinString(rq,人员姓名)from
(
select人员姓名,CONVERT(varchar(100),刷卡日期时间,23)asrq,
CONVERT(varchar(100),刷卡日期时间,24)assj
from你的表名
)tgroupby人员姓名,rq