我创建了一个存储过程,如下所示:
ALTER PROCEDURE reminders
AS
BEGIN
SET NOCOUNT ON;
DECLARE @MyDate DATE,
@FirstDate DATE,
@LastDate DATE
SELECT @MyDate = Getdate()
SELECT @FirstDate = CONVERT(VARCHAR(25), Dateadd(dd, -( Day(@mydate) - 1 ), @mydate), 100), @LastDate = CONVERT(VARCHAR(25), Dateadd(dd, -( Day( Dateadd(mm, 1, @mydate)) ),
Dateadd(mm, 1, @mydate)), 100)
DECLARE @AllDates TABLE
(
datevalue DATE
)
DECLARE @Lastday INT
SET @Lastday = Datepart(d, @LastDate)
DECLARE @Days INT
SET @Days = 1
WHILE @Days <= @Lastday
BEGIN
INSERT INTO @AllDates
SELECT @FirstDate
SET @FirstDate = Dateadd(d, 1, @FirstDate)
SET @Days = @Days + 1
END
SELECT AD.datevalue
FROM @AllDates AD
LEFT OUTER JOIN EmpLog EL
ON AD.datevalue = EL.Date
LEFT OUTER JOIN holiday H
ON AD.datevalue = H.Date
WHERE EL.Date IS NULL
AND H.Date IS NULL
AND DATENAME(dw,AD.DateValue) NOT IN ('Saturday','Sunday')
END
我需要的是输出不应该包括未来的日子。Ex Date today 是12-21-2012
,该代码的输出包括 12-22-2012 到 12-31-2012,而且,我希望代码仅在当前日期前 16 天输出。前任。今天的日期是12-21-2012
这样,该代码的输出将是 11 月 30 日到 12 月 21 日,不包括节假日和周末。
谢谢