7
兩個日期日期我想兩個日期CTE TO之間獲得使用SQL Server
之間取缺少的日期說@maxDate=2013-01-28
說@curDate= GetDate()
我已經寫CTE做到這一點。這裏是我的CTE:
create procedure EmpDate
as begin
declare @curDate Date
set @curDate = GETDATE()
declare @maxDate Date
select @maxDate = MAX(EmpAttendance.Sdate)
from EmpAttendance
;with GetDates As
(
select 1 as counter, @maxDate as Date
UNION ALL
select counter + 1, DATEADD(day,counter,@maxDate)
from GetDates
where DATEADD(day, counter, @maxDate) < @curDate
)
select Date from GetDates
end
go
這樣做的結果是
Date
2013-01-28
2013-01-29
2013-01-30
,但我想
2013-01-29
2013-01-30
請幫我
在此先感謝
+1:打我給它。 –