首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

经过SQL来实现日期明细

2013-07-11 
通过SQL来实现日期明细我有一个表,存着员工和请假时间,数据表格式如下nameholiday_begin_dateholiday_end_

通过SQL来实现日期明细
我有一个表,存着员工和请假时间,数据表格式如下
name    holiday_begin_date     holiday_end_date
  A         2013-01-16       2013-02-16
  b         2013-02-05       2013-02-05
  c         2013-02-15       2013-02-17
  ..        ............       ...........(以下数据省略)

假设,现在是2月份
现在想通过SQL来判断,2月的1~28号,所有员工的休假明细
即想通过当月的日期明细来left join 休假明细.

目前休假明细实现不了,请指教。谢谢

[解决办法]


Create function [dbo].[generateTime]
 
(
 
    @begin_date datetime,
 
    @end_date datetime
 
)

returns @t table(date datetime)
 
as
 
begin
 
    with maco as
 
    (
 
       select @begin_date AS date
 
       union all
 
       select maco.date+1  as date from maco
 
       where date+1 <=@end_date
 
    )
 
    insert into @t
 
    select * from maco option(maxrecursion 0);
 
    return
 
end

go
select * from dbo.generateTime('2013-2-1','2013-2-28')

热点排行