If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > EXTRACTING THE DATE FIELD in DB2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-10-04, 02:50
anuindia anuindia is offline
Registered User
 
Join Date: Oct 2003
Posts: 23
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
Reply With Quote
  #2 (permalink)  
Old 02-10-04, 03:57
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
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
Reply With Quote
  #3 (permalink)  
Old 02-10-04, 09:01
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Re: EXTRACTING THE DATE FIELD in DB2

Quote:
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?
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On