FUNCTION "<System>"."<Package>::<Table Function>" (TIMEID VARCHAR(32))
RETURNS TABLE (TIME VARCHAR(32),
TIMEID VARCHAR(32),
PREVIOUSTIMEID VARCHAR(32),
STARTOFMONTH VARCHAR(32),
ENDOFMONTH VARCHAR(32),
NUMBEROFDAYS VARCHAR(32),
NUMBEROFWEEKS VARCHAR(32))
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER AS
BEGIN
-------code explained in subsequent steps go here-------
<insert your code here>
RETURN
:LT_DATE;
END;
Date_time = SELECT
TIME,
TIMEID,
PREVIOUSTIMEID,
STARTOFMONTH,
ENDOFMONTH,
FROM
<Time Master Data Table>
WHERE
TIMEID = < Entered Time ID> AND
TIMELEVEL = ‘MONTH’
LIMIT 19;
CASE WHEN TIMEID LIKE '____0100'
THEN (TIMEID - 8900)
ELSE (TIMEID - 100)
END AS PREVIOUSTIMEID
TO_CHAR (ADD_DAYS (TO_DATE ('1900/01/01', 'YYYY/MM/DD'),
CAST (<ENDOFMONTH Signed data> AS numeric)-2), 'MM/DD/YYYY')
TO_CHAR (ADD_DAYS (ENDOFMONTH, 1), 'MM/DD/YYYY')
LT_DATE = SELECT
Date1.TIME AS TIME,
Date1.TIMEID AS TIMEID,
Date1.PREVIOUSTIMEID AS PREVIOUSTIMEID,
Date2.STARTOFMONTH AS STARTOFMONTH,
Date1.ENDOFMONTH AS ENDOFMONTH,
Date1.NUMBEROFDAYS AS NUMBEROFDAYS,
Date1.NUMBEROFWEEKS AS NUMBEROFWEEKS
FROM
:Date_time AS Date1
INNER JOIN
:Date_time AS Date2
ON
Date2.TIMEID = Date1.PREVIOUSTIMEID;
RETURN
:LT_DATE;
DAYS_BETWEEN (TO_DATE(STARTOFMONTH,'MM/DD/YYYY'),
TO_DATE(EOM,'MM/DD/YYYY')) + 1
(DAYS_BETWEEN (TO_DATE(STARTOFMONTH,'MM/DD/YYYY'),
TO_DATE(EOM,'MM/DD/YYYY')) + 1) / 7
FUNCTION "<System>"."<Package>::<Table Function>" (TIMEID VARCHAR(32))
RETURNS TABLE (TIME VARCHAR(32),
TIMEID VARCHAR(32),
PREVIOUSTIMEID VARCHAR(32),
STARTOFMONTH VARCHAR(32),
ENDOFMONTH VARCHAR(32),
NUMBEROFDAYS VARCHAR(32),
NUMBEROFWEEKS VARCHAR(32))
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER AS
BEGIN
LT_DATE = WITH DATE_TIME AS
( SELECT
TIME,
TIMEID,
PREVIOUSTIMEID,
TO_CHAR(ADD_DAYS(ENDOFMONTH, 1), 'MM/DD/YYYY') AS STARTOFMONTH,
TO_CHAR(ENDOFMONTH, 'MM/DD/YYYY') AS ENDOFMONTH,
FROM ( SELECT
<Time period> AS TIME,
<Time id> AS TIMEID,
CASE
WHEN <Time id> LIKE '____0100'
THEN ( <Time id> - 8900)
ELSE ( <Time id> - 100)
END AS PREVIOUSTIMEID,
TO_CHAR(ADD_DAYS(TO_DATE('1900/01/01','YYYY/MM/DD'),
CAST(<End of month> AS numeric)-2),
'YYYY/MM/DD') AS ENDOFMONTH
FROM
<TIME MASTER DATA TABLE> AS MD
WHERE
<TIME LEVEL> = 'MONTH' AND
<TIME TIMEID> >= TIMEID (Input Parameter)
ORDER BY <TIME TIMEID> ASC
LIMIT 19)
)
SELECT
DATE1.TIME,
DATE1.TIMEID,
DATE1.PREVIOUSTIMEID,
DATE2.STARTOFMONTH,
DATE1.ENDOFMONTH,
(DAYS_BETWEEN (TO_DATE(DATE2.STARTOFMONTH,'MM/DD/YYYY'),
TO_DATE(DATE1.ENDOFMONTH,'MM/DD/YYYY')) + 1) AS NUMBEROFDAYS,
(DAYS_BETWEEN (TO_DATE(DATE2.STARTOFMONTH,'MM/DD/YYYY'),
TO_DATE(DATE1.ENDOFMONTH,'MM/DD/YYYY')) + 1) / 7 AS NUMBEROFWEEKS
FROM
DATE_TIME AS DATE1
INNER JOIN
DATE_TIME AS DATE2
ON
DATE2.TIMEID = DATE1.PREV_TIMEID;
RETURN
:LT_DATE;
END;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 | |
1 |