Auto generating date sequence
577737May 15 2007 — edited May 15 2007Hello to the community
I have the task to auto generate date sequences, such that I have to select the friday of each week. The friday date generated cannot exceed the friday of the current week (given any starting point). On another forum I found a code, but the one shown here is modified. Since I am completely new to functions in Apex, here is my code
CREATE OR REPLACE FNSEQDATES( lowlimit in DATE, highlimit in DATE)
RETURN DATE
IS
value
BEGIN
IF lowlimit > highlimit
set temp = lowlimit
lowlimit = highlimit
highlimit = temp;
END IF;
INSERT INTO value VALUES (lowlimit)
WHILE ROWCOUNT > 0
INSERT INTO value SELECT DATEADD(dd, t.items, d.value)
FROM value d CROSS JOIN (SELECT COUNT(*) items FROM value) t
WHERE DATEADD(dd, t.items, d.value) <= highlimit
RETURN value
END;
and then maybe call the following statement, to generate dates
SELECT value FROM FNSEQDATES('1/1/2006', '3/31/2006' ) WHERE DATEPART(dw, value) = 6 and value <= '5/31/2007'
Clearly, my function is incorrect (psst.. it doesnt work). I was wondering if someone could assist me in solving this little tiny issue. Cheers.