IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Retrieve rows that are between two date


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
i_suman

New User


Joined: 01 Mar 2005
Posts: 20

PostPosted: Sat Oct 25, 2008 7:05 pm
Reply with quote

I want to retrieve rows that are between two dates.

I used BETWEEN for this query. Like, BETWEEN date1 AND date2. However we can also use <= and > symbols, instead.

Could some one tell which option to choose to improve the performance of the query? Is it BETWEEN or <, > symbols.

Thanks
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Oct 25, 2008 9:22 pm
Reply with quote

Hello,

You should work with your dba to determine which is best for your particular situation.
Back to top
View user's profile Send private message
nabarundas

New User


Joined: 21 Jun 2007
Posts: 28
Location: pune

PostPosted: Wed Oct 29, 2008 2:19 pm
Reply with quote

Try the bellow query:

select * from <Tablename> where days(<day_col_name>) between days(date('yyyy-mm-dd')) and days(date('yyyy-mm-dd'))


also check out the following link

www.ibm.com/developerworks/db2/library/techarticle/0211yip/0211yip3.html


Regards,
Nabarun
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Wed Oct 29, 2008 2:28 pm
Reply with quote

The TS does know how to write the query...

the question is about a performance issue

case 1 ) something between limit1 and limit2
case 2 ) something > limit1 and thesamesomehing < limit2

the result set is the same, but the DB2 retrieval path might be different
full tablescan vs. index use
Back to top
View user's profile Send private message
nabarundas

New User


Joined: 21 Jun 2007
Posts: 28
Location: pune

PostPosted: Wed Oct 29, 2008 2:33 pm
Reply with quote

I am sorry. I misjudged the question.


Regards,
Nabarun
Back to top
View user's profile Send private message
muthuvel

Active User


Joined: 29 Nov 2005
Posts: 217
Location: Canada

PostPosted: Wed Oct 29, 2008 2:44 pm
Reply with quote

When i had the same situation of selecting the current day's inserted or updated record which was fetched by using Update Timestamp in table.
My DBA recommended BETWEEN is better than <,> for performance .

So as earler mentioned by Dick,your DBA can give you the 'best' solution than us.
Back to top
View user's profile Send private message
dharmendra_kp

New User


Joined: 10 Mar 2005
Posts: 33
Location: Lewiston

PostPosted: Wed Oct 29, 2008 6:21 pm
Reply with quote

And DBA takes the decision based on the table structure and nature of data population. For example if that date column is part of the key and or an index is defined on that or that date column is say record update date then between will work better. If that date column is something like record insert date then most likey > < is going to be more efficient.
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Wed Oct 29, 2008 7:34 pm
Reply with quote

Hi, this Link might help

ibmmainframes.com/viewtopic.php?t=33315&highlight=

Cris
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Need to convert date format DFSORT/ICETOOL 20
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
Search our Forums:

Back to Top