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 > Simple Date Query Not So Simple

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-20-09, 10:04
icurschwarz icurschwarz is offline
Registered User
 
Join Date: May 2009
Posts: 2
Simple Date Query Not So Simple

I'm fairly new to SQL and to this point my experience is mostly limited to Access. However, I'm trying to create a pass through query to a DB2 table and I'm having all kinds of headaches trying to set it up.

The query is very simple:

Code:
SELECT *
FROM TABLENAME.REQT
WHERE REQT_TMSP > '2006-01-01'
The REQT_TMSP field is a time stamp of when that request record was added to the table and when I view the table the format is:

MM/DD/YYYY 00:00:00 AM/PM

I've tried a ton of stuff to get this query to work but I keep getting syntax related errors. There is probably something very basic that I am missing but I can't seem to figure it out and I'm not finding much in Google that's helping.

Any ideas?
Reply With Quote
  #2 (permalink)  
Old 05-20-09, 10:13
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
icurschwarz, the timestamp format in DB2 is:

'YYYY-MM-DD-HH.MM.SS.000000'
(The last 6 digits are the micro seconds).

There are a few ways to fix your query.

WHERE REQT_TMSP > TIMESTAMP('2006-01-01', '24.00.00')
WHERE REQT_TMSP > '2006-01-01-24.00.00.000000'
(I don't recommend the next one if REQT_TMSP is indexed or could be indexed.)
WHERE DATE(REQT_TMSP) > '2006-01-01'

Where are you viewing the result that shows the AM/PM in the Timestamp?
Reply With Quote
  #3 (permalink)  
Old 05-20-09, 13:11
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
Don't mix up TIMESTAMP, DATE, and TIME values. They serve different purposes and cannot directly be compared (for good reasons).
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
  #4 (permalink)  
Old 05-20-09, 13:29
icurschwarz icurschwarz is offline
Registered User
 
Join Date: May 2009
Posts: 2
Thanks guys. That was what I needed.
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