-- Most companies use calendars that start on Saturday, Sunday, Monday. The
-- weekend date is based on the week start date. This query can be used to
-- create dates for a calendar such as a ERP GL Calendar or any company
-- specific fiscal calendar.
WITH q_dates AS
DUAL CONNECT BY level <= 7*&i_wk
-- The input to the above query is the begining of the week - First
-- Saturday of the year (01/03/2015) and the number of weeks is setup to
-- be 52. The week ending dates are Friday dates corresponding to the
-- prior Saturday dates as computed by the query. Partial output is
-- shown below.
-- To create calendar dates for multiple years, PL/SQL code would be a
-- better option with the use of FOR or WHILE LOOP syntax with the
-- ability to reset variables at completion of a year.