Using the DPART Function in SQL Generation

The DPART FOCUS function, which extracts a specified component from a date field and returns it in numeric format, can be passed to SQL for improved performance.

The syntax is:

DPART (value, 'component', outfield)

where:

value

Is an input parameter (date) which can be a constant or a variable in one of the following formats:

component

Is one from the subset of components that can be specified as:

Formats are case-sensitive.

outfield

Is an integer variable or an I format enclosed in single quotes.

If any input errors are made, a value of zero will be returned.

For more information, see Optimization of the HPART, DPART, HDIFF, HDATE, and DATEDIF Functions.


Top of page

Example: Extracting a Component From a Date Field
DEFINE FILE CAR
DATE/YYMD = IF COUNTRY IS 'ENGLAND' THEN '1941 DEC 7' ELSE DATE
+ 30;
YEAR/I11 = DPART(DATE, 'YEAR', 'I11');
MONTH/I11 = DPART(DATE, 'MM', 'I11');
DAY/I11 = DPART(DATE, 'DAY', 'I11');
END
TABLE FILE CAR
PRINT COUNTRY DATE YEAR MONTH DAY
END
COUNTRY DATE YEAR MONTH DAY
------- ---- ---- ----- ---
ENGLAND 1941/12/07 1941 12 7
JAPAN 1942/01/06 1942 1 6
ITALY 1942/02/05 1942 2 5
W GERMANY 1942/03/07 1942 3 7
FRANCE 1942/04/06 1942 4 6
>>

Information Builders