Solved

timestamp function in db2

Posted on 2009-07-13
4
3,398 Views
Last Modified: 2012-08-14
I found strange things when using timestamp funtion in writing a query for db2 sql that had the following clause in the sql statement
AND   timestamp('2009-06-01','00:00:00') <=  startdatetime AND   StartDateTime < timestamp(date('2009-06-30') + 1 day,'00:00:00')

same above statement when it was written as follows
AND startdatetime >= '2009-06-01-00.00.00' and startdatetime <= '2009-06-30-00.00.00' - produced different results  - first one produced more aggregate records for evaluation then the second - what differences that db2 does in using a timestamp fuction as against direct comparisons of datetime field? (startdatetime is defined as timestamp of length 10)
0
Comment
Question by:mahjag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 18

Expert Comment

by:Dave Ford
ID: 24843866

On one clause you have "less-than", but on the other clause you have "less-than-or-equal-to"

HTH,
DaveSlash


0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 24843951
Hi mahjag,

What Dave said.

Also, the format of the datetime is incorrect.  The value '2009-06-01-00.00.00'  should be '2009-06-01.00.00.00'.  Note that a period should separate the date and time values, not a hyphen.  An improperly formatted datetime will affect the comparison in an ugly way.


Good Luck,
Kent
0
 
LVL 18

Accepted Solution

by:
Dave Ford earned 125 total points
ID: 24844353

That's realy interesting.  ( see below )

On DB2 for i, this works:
 
select *
from   deleteme
where  aTS >= '2009-07-01-00.00.00'
  and  aTS <= '2009-07-31-00.00.00'
;
 
But, this doesn't:
 
select *
from   deleteme
where  aTS >= '2009-07-01.00.00.00'
  and  aTS <= '2009-07-31.00.00.00'
;
 
[SQL0180] Syntax of date, time, or timestamp value not valid.

Open in new window

0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 24845151
Hi Dave,

Wow.  I've had scads of queries fail due to badly formatted date, time and/or datetime values.  I've never seen the behavior where a timestamp was accepted in that format.

Of course, I'm an LUW kind of guy.   :)    (Where a full timestamp really needs microseconds ('.000000') appended after the time.)


Kent
0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question