Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    23

    Unanswered: EXTRACTING THE DATE FIELD in DB2

    Hi,

    I am using DB2 database and VB6 on Win XP. I need to select records from Database for some particular month. I am trying to extract YEAR from DATE field (named as INV_DATE) in database table INVOICE using the following code.


    strqueryDate = "SELECT EXTRACT (YEAR from INV_DATE) from INVOICE where EXTRACT(YEAR from INV_DATE) = " + CStr(intYear) + ""

    Set localrecordsetDate = AGFDB.CONAGF.Execute(strqueryDate)
    totalRecCountDate = localrecordsetDate.RecordCount

    this query runs well on DB2 database command window but while executing in code it gives me following error:

    Run-time error '-2147217900(80040e14)':
    [Microsoft][ODBC dBase Driver] Syntax error (missing operator) in query expression 'EXTRACT(YEAR from INV_DATE)'.


    I am not able to understand what is wrong. Please help

    Anurag

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    I would check out the DB2 SQL Reference manual. I don't see the EXTRACT function in the DB2 manual. You can try the following:

    SELECT YEAR(INV_DATE) from INVOICE

    This will return an integer value. If you want character, you can CAST it or maybe use the CHAR function.
    M. A. Feldman
    IBM Certified DBA on DB2 for Linux, UNIX, and Windows
    IBM Certified DBA on DB2 for z/OS and OS/390

  3. #3
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1

    Re: EXTRACTING THE DATE FIELD in DB2

    Originally posted by anuindia

    I am using DB2 database and VB6 on Win XP.

    ...

    Run-time error '-2147217900(80040e14)':
    [Microsoft][ODBC dBase Driver] Syntax error (missing operator) in query expression 'EXTRACT(YEAR from INV_DATE)'.

    Are you sure you're using DB2? Why then your ODBC driver is for dBase?

Posting Permissions

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