表结构如下
日期,上班,下班
20100506  08:01  17:00
20100506  07:41  17:20
20100506  07:51  16:00需要拉出这样的数据表,在旁边加上迟到或早退备注
如20100506  08:01  17:00  迟到上班>8:00迟到
下班<17:00 早退

解决方案 »

  1.   

    select *,case when convert(varchar(5),上班,14)>'08:00' then 
    case when convert(varchar(5),下班,14)<'17:00' then '迟到+早退' else '迟到' end
    when convert(varchar(5),下班,14)<'17:00' then '早退' end
    from tb
      

  2.   

    select *,case when cast(上班 as varchar(5))>'08:00' then '迟到' else '' end as re1
    ,case when cast(下班 as varchar(5))<'17:00' then '早退' else '' end as re2
    from tb
      

  3.   

    select 日期,case when 上班>'08:00' then 上班+' 迟到' esle 上班 end 上班,
    case when 下班<'17:00' then 下班+' 早退' esle 下班 end 下班
    from tablea