I guess he wants every third Sunday from the start date, not every third Sunday of the month. I had the same misunderstanding. But, I like your method better than creating a table with every date between now and some arbitrary future date.
CREATE PROCEDURE RecurringDates_ThirdSunday
(
@Start DATETIME,
@End DATETIME
)
AS
DECLARE @curDt DATETIME
SET @curDt = @Start
DECLARE @t TABLE (GoodDate DATETIME NOT NULL)
WHILE DATEPART(dw,@curDt) != 1
BEGIN
SET @curDt = DATEADD(dd,1,@CurDt)
END
SET @curDt = DATEADD(dd,14,@CurDt)
WHILE @curDt <= @End
BEGIN
INSERT INTO @t (GoodDate) VALUES (@curDt)
SET @curDt = DATEADD(dd,21,@CurDt)
END
SELECT \*
FROM @t
--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters