我有2张表,一个是考勤记录表,一个是请假申请表。
我要查出考勤表里 所有 时间字段>8:30 并且<17:30 的数据 不考虑时间字段的里的年月日。
查出来的是迟到的人的数据,但同时我要去请假申请表做比较,如果里面有name和日期字段相同的数据都要排除,
苦想了许久,望有高手给与指点!!!

解决方案 »

  1.   

    select name,convert(char(10),时间,120)
    from 考勤记录表 t
    where right(convert(char(16),时间,120),5) between '08:30' and '17:30'
    and not exists
    (select 1 from 请假申请表 where name=t.name and 日期=convert(char(10),t.时间,120))
      

  2.   

    select * from 考勤记录表 a where convert(varchar(5),考勤time,108) between '08:30' and '17:30'
     and not exists(select 1 from  请假申请表 b where a.姓名=b.姓名 and convert(varchar(10),请假time,120)=convert(varchar(10),a.考勤time,120) )
      

  3.   

    select *
    from 考勤记录表 t
    where (CONVERT(char(5),时间,108) between '08:30' and '17:30')
    and not exists
    (select 1 from 请假申请表 where name=t.name and DATEDIFF(dd,日期,t.时间)=0)
      

  4.   

    感谢楼上的3位,我还是有点小问题,现在吧我的问题解释的再清楚一点,麻烦再帮帮我,稍后会把分给上。
    简单说下我的表结构吧
    考勤表o_kaoqin包含name 和 time(保存进去的时间样式如2010-10-10 10:00:00)
    请假表申请 o_shenqing包含 name 和 time (保存格式如上)
    我要查出的是o_kaoqin表里 时间超过9:30分迟到的界限到12:30,并且在o_shenqing表里time对比只要日期不用精确到时分秒,只要对比日期,这表里没有的所有数据,也就是请过假的就不用查出来了。