LAST
Purpose
Returns the last value of the Period argument (that is, the ending bound minus one granule of the element type of the argument).
Syntax
where:
Syntax element... |
Specifies... |
period_expression |
any expression that evaluates to a Period data type. |
derived_period |
any expression that evaluated to a derived period. |
Return Value
The result type of the LAST function is same as the element type of the Period expression or the data type of the begin or end column if the argument is a derived period. If the argument is NULL, the result is NULL.
Format and Title
The format is the default format for the element type of the Period expression or the format of the begin or end column if the argument is a derived period.
Error Conditions
If an argument has a data type other than a Period data type, an error is reported.
Example
Assume the following query is executed on the employee table PERIOD(DATE) column period1:
SELECT * FROM employee WHERE LAST(period1) = DATE '2004-01-04';
ename dept period1
----- ----------- ----------------------------
Jones Sales ('2004-01-02', '2004-01-05')
Adams Marketing ('2004-06-19', '2005-02-09')
Mary Development ('2004-06-19', '2005-01-05')
Simon Sales ('2004-06-22', '2005-01-07')
The result is:
ename dept period1
----- ----------- ----------------------------
Jones Sales ('2004-01-02', '2004-01-05')
Example
LAST returns the last value of a derived period called jobduration created by the following SQL statement:
CREATE TABLE employee(id INTEGER,
name VARCHAR(50),
jdbegin DATE NOT NULL FORMAT 'YYYY-MM-DD',
jdend DATE NOT NULL FORMAT 'YYYY-MM-DD',
PERIOD FOR jobduration(jdbegin,jdend)
)PRIMARY INDEX(id);
When the following values are inserted into the employee table:
INSERT INTO employee(1025,'John',DATE'2011-01-02',DATE'2012-05-02');
the following SQL statement:
SELECT LAST (jobduration) FROM employee;
returns:
LAST(jobduration)
------------------------
2012-05-01