補全未出勤日期

-- 建立测试环境
set  nocount  on
create   table  test(Name  varchar ( 20 ),Date  varchar ( 20 ),Time1  varchar ( 20 ),Time2  varchar ( 20 ))
insert   into  test  select   ' xxxx ' , ' 2008-2-1 ' , ' 08:00 ' , ' 17:00 '
insert   into  test  select   ' xxxx ' , ' 2008-2-9 ' , ' 08:00 ' , Null
insert   into  test  select   ' xxxx ' , ' 2008-2-28 ' , ' 08:00 ' , ' 17:00 '
go
-- 测试

select    case   when   isdate (date) > 0   then  name  else   ' - '   end  EmpName,
        
case   when   isdate (date) > 0   then  date  else   ' - '   end  IODate,
        Time1,Time2
    
from (
select  ( select   max (name)  from  test)name,
(
select   cast ( year ( max ( cast (date  as   datetime )))  as   varchar ( 4 )) + ' - ' +
        
cast ( month ( max ( cast (date  as   datetime )))  as   varchar ( 2 )) + ' - ' +
        
cast (b.dd  as   varchar ( 2 ))  from  test)date,
        
isnull (time1, ' - ' ) time1, isnull (time2, ' - ' ) time2
 
 
from  test a
right   join ( select   1   as  dd  union   select   2   union   select   3   union   select   4   union   select   5   union
    
select   6   union   select   7   union   select   8   union   select   9   union   select   10   union
    
select   11   union   select   12   union   select   13   union   select   14   union   select   15   union
    
select   16   union   select   17   union   select   18   union   select   19   union   select   20   union
    
select   21   union   select   22   union   select   23   union   select   24   union   select   25   union
    
select   26   union   select   27   union   select   28   union   select   29   union   select   30   union
    
select   31 ) b
on   day ( cast (date  as   datetime )) = b.dd)a


-- 删除测试环境
drop   table  test
 
set  nocount  off
/*
EmpName              IODate     Time1                Time2                
-------------------- ---------- -------------------- -------------------- 
xxxx                 2008-2-1   08:00                17:00
xxxx                 2008-2-2   -                    -
xxxx                 2008-2-3   -                    -
xxxx                 2008-2-4   -                    -
xxxx                 2008-2-5   -                    -
xxxx                 2008-2-6   -                    -
xxxx                 2008-2-7   -                    -
xxxx                 2008-2-8   -                    -
xxxx                 2008-2-9   08:00                -
xxxx                 2008-2-10  -                    -
xxxx                 2008-2-11  -                    -
xxxx                 2008-2-12  -                    -
xxxx                 2008-2-13  -                    -
xxxx                 2008-2-14  -                    -
xxxx                 2008-2-15  -                    -
xxxx                 2008-2-16  -                    -
xxxx                 2008-2-17  -                    -
xxxx                 2008-2-18  -                    -
xxxx                 2008-2-19  -                    -
xxxx                 2008-2-20  -                    -
xxxx                 2008-2-21  -                    -
xxxx                 2008-2-22  -                    -
xxxx                 2008-2-23  -                    -
xxxx                 2008-2-24  -                    -
xxxx                 2008-2-25  -                    -
xxxx                 2008-2-26  -                    -
xxxx                 2008-2-27  -                    -
xxxx                 2008-2-28  08:00                17:00
xxxx                 2008-2-29  -                    -
-                    -          -                    -
-                    -          -                    -
*/


水晶報表做法參考: http://www.cnblogs.com/babyt/archive/2008/05/11/1192770.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值