Home > Ask the AS/400 Experts > DB2/400 and DB2 UDB Questions & Answers > Change from a Julian date to a "true" date for a search criteria index
Ask The iSeries 400 Expert: Questions & Answers
EMAIL THIS

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

Kent Milligan EXPERT RESPONSE FROM: Kent Milligan

Pose a Question
Other iSeries 400 Categories
Meet all iSeries 400 Experts
Become an Expert for this site


iSeries news and advice
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


>
QUESTION POSED ON: 30 October 2008
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.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google



RELATED CONTENT
DB2/400 and DB2 UDB
When is the YES option for 'reuse deleted files' function the best choice?
Monitoring members 'stuck' within a physical file on an EDI system
Developing tables in a parent-child relationship in DB2
SQL server error message -321
Creating a host variable of the 'where in' statement in SQL
Choose which column names are returned via ODBC when working with DB2 files
Allow access to data from a stored procedure result set using COBOL or RPG
Access path and an open data path differences
Convert a numeric physical file to a character in SQL without leading zeros
Inserting data from a CTE into a file in SQL

iSeries database management
Deleting records in SQL database files when fields are duplicated in another file
Using CHGPF to change file attributes of core application files
How to summarize an alias reference outside of SQL views and MQTs
The enhanced DB2 inside i5/OS V6R1
iSeries database management Research

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



iSeries Networking - Printing, Remote Access, TCP/IP
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2010, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts