Ask the Expert

Change from a Julian date to a "true" date for a search criteria index

When using the create index command on the AS/400, can you manipulate a Julian date to be a "true" date? So if you were to query that file (index) you could use that "true" date field in the index in your search criteria?
With V6R1, the SQL CREATE INDEX statement does allow you to create an index over an expression. The following index would convert a Julian date value stored in a decimal field into a date value which would be used as the index key value.

  Create Index mydate_ix on pf1 
      (date( case when substr(digits(jdatcol),1,2) > 
      '39' then '19' else '20' end concat digits(jdatcol)) ) 
However, the SQL standard prevents indexes from being referenced on an SQL query. So it would be better to move this derivation to an SQL view and then write your queries against the SQL view. Here's an example SQL view and a sample SELECT statement demonstrating how to query the view.

Create View myview as 
    (select col1, date( case when substr(digits(jdatcol),1,2) >
       '39' then '19' else '20' end concat digits(jdatcol)) 
  as datcol, col3 from pf1) 

SELECT col1 FROM myview where jdatcol >= CURRENT DATE 
Another alternative would be changing your physical file definition to change the Julian date column to a real date column. Then, you could create a LF that maps the date column back to it's original form. Existing applications could be changed to use the logical file and not have to be modified to support the date data type. All of your queries would then just reference the date field in the physical file.

This was first published in January 2009

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: