SQL/MP Query Guide
Retrieving Data: How to Write Queries
HP NonStop SQL/MP Query Guide—524488-003
1-22
Accessing Date-Time Values
Accessing Date-Time Values
For these examples, suppose that the PROJECTS table contains the data shown in
Table 1-2. The WAIT_TIME column specifies a number of days.
This query accesses two rows of the PROJECTS table:
SELECT * FROM PROJECTS
WHERE PROJECT_NAME = "134"
OR PROJECT_NAME = "920" ;
The query returns this result:
PROJECT_NAME START_DATE END_DATE WAIT_TIME
------------ ---------------- ---------------- ---------
920 1988-02-21:20:30 1989-03-21:20:30 20
134 1970-01-01:00:00 1992-01-29:20:30 30
--- 2 row(s) selected.
Adding an INTERVAL Value to a DATETIME Value
This example adds an INTERVAL value with a YEAR value to a DATETIME value:
SELECT end_date + INTERVAL "1" YEAR
FROM projects
WHERE project_name = "922" ;
The query returns this result:
(EXPR)
--------------
1992-01-20:12:30
The next example adds an INTERVAL value (WAIT_TIME) to a DATETIME value
(START_DATE). The system handles 1988 as a leap year.
SELECT start_date + wait_time
FROM projects
WHERE project_name = "920" ;
Table 1-2. Sample Table for Date-Time and INTERVAL Arithmetic Examples
project_name start_date end_date wait_time
920 1988-02-21:20:30 1989-03-21:20:30 20
134 1970-01-01:00:00 1992-01-29:20:30 30
922 1940-02-21:12:30 1991-01-20:12:30 13
955 1990-10-14:14:30 1991-01-20:12:30 14
945 1989-10-20:00:00 1990-10-21:00:00 30