求工作日历的存贮过程或者函数?
求工作日历的存贮过程或者函数?
如:2007-01-01 到2007-12-31 之间的所有天数明细?
2007-01-01
2007-01-02
2007-01-03
2007-01-04
。。。。。
2007-12-31
??
------解决方案--------------------Create Procedure SP_TEST
(@StartDate DateTime,
@EndDate DateTime)
As
Begin
Select Top 1000 Identity(Int, 0, 1) As ID Into #T from Sysobjects A, Sysobjects B
Select Convert(Varchar(10), DateAdd(dd, ID, @StartDate), 120) As 日期 From #T Where ID <= DateDiff(dd, @StartDate, @EndDate)
Drop Table #T
End
GO
EXEC SP_TEST '2007-01-01 ', '2007-12-31 '
GO
Drop Procedure SP_TEST
------解决方案--------------------declare @t table(tim datetime)
declare @starttime datetime
declare @endtime datetime
select @starttime= '2007-01-01 ',@endtime= '2007-12-31 '
while @starttime <=@endtime
begin
insert into @t
select @starttime
set @starttime=dateadd(day,1,@starttime)
end
select * from @t