Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2008

    Question Unanswered: DB2 Date vs Unix System Date

    In the following Korn shell script, I am attempting to get a count all of the rows from a db2 table in which the PROCESS_DT is equal to yesterday's UNIX system date. The script runs without error, but returns a count of 0 when I am 100% certain that there are over 3 millions records with a PROCESS_DT equal to yesterday's date. Does any one have any suggestions?

    DATE_STAMP=`TZ=CST+24 date +%Y-%m-%d`
    RecCount='db2 -x "select count(*) from schema.tablename where PROCESS_DT=DATE("$DATE_STAMP")`
    echo "$RecCount"
    echo "$DATE_STAMP"

  2. #2
    Join Date
    Jan 2007
    Jena, Germany
    You should verify that the string in "DATE_STAMP" is actually a valid string representation for a date value. Next, you have to have single-quotes in the SQL statement to get the string as string to DB2, i.e. something like:
    db2 -x "select count(*) from schema.tablename where PROCESS_DT=DATE('$DATE_STAMP')
    Also, you have a single-quote in next to "RecCount=" but a back-tick at the end. This can't work anyway.
    Knut Stolze
    IBM DB2 Analytics Accelerator
    IBM Germany Research & Development

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts