CREATE TABLE [Digits] (
[DigitID] [int] NOT NULL ,
CONSTRAINT [PK_Digits] PRIMARY KEY CLUSTERED
(
[DigitID]
) ON [PRIMARY]
) ON [PRIMARY]
GO
DECLARE @position int
SET @position = 1
WHILE @position <= 1000
BEGIN
insert into Digits(DigitID) values (@position)
SET @position = @position + 1
END
go
Create procedure NextWhatDay
@Dayofweek int,
@week int
As
SELECT DATEADD(d, DigitID, GETDATE()) AS Dayofweek
FROM Digits
WHERE (DATEPART(dw, DATEADD(d, DigitID, GETDATE())) = @Dayofweek)
AND (DATEADD(d, DigitID, GETDATE()) <= DATEADD(wk, @week, GETDATE()))
Return
NextWhatDay 3,7 --for next 7 tusdays
NextWhatDay 2,100 --for next 100 mondays