Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
SQL query with between for Dates fetches no records

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
View previous topic :: :: View next topic  
Author Message
rakesh17684

New User


Joined: 08 Oct 2006
Posts: 60
Location: San Diego

PostPosted: Fri Jul 25, 2008 11:33 am    Post subject: SQL query with between for Dates fetches no records
Reply with quote

i have a SQL in which i fetch records based on a date range.
i use a 'between' in the where clause of the query. when the start date is greater than the end date in the query i get no rows but vice versa i get the records i want.

why is that ??

SELECT * FROM table1
WHERE date BETWEEN '2008-01-01' and '2008-02-20'; ---> icon_smile.gif
i get the records

SELECT * FROM table1
WHERE date BETWEEN '2008-02-20' and '2008-01-01' ; ---> icon_sad.gif
No records fetched
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Jul 25, 2008 1:03 pm    Post subject:
Reply with quote

If a date is >= '2008-02-20' it can not be <= '2008-01-01'!
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri Jul 25, 2008 2:44 pm    Post subject:
Reply with quote

COL BETWEEN A AND B is equivalent to COL >= A AND COL <= B
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Fri Jul 25, 2008 8:10 pm    Post subject:
Reply with quote

Hello,

Quote:
SELECT * FROM table1
WHERE date BETWEEN '2008-02-20' and '2008-01-01' ; ---> icon_sad.gif
No records fetched
The time to be concerned would be if any rows were returned. . . icon_smile.gif
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Sat Jul 26, 2008 5:13 am    Post subject:
Reply with quote

Don't confuse the square root of -1 with SQL, Dick. icon_lol.gif
Back to top
View user's profile Send private message
vini_srcna

Active User


Joined: 26 May 2005
Posts: 178
Location: Copenhagen, Denmark

PostPosted: Mon Jul 28, 2008 6:17 pm    Post subject:
Reply with quote

Thats how it is defined to work icon_smile.gif
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 271
Location: Mumbai

PostPosted: Fri Aug 01, 2008 11:20 am    Post subject:
Reply with quote

It won't Display any row if you execute the query like
SELECT * FROM table1
WHERE date BETWEEN '2008-02-20' and '2008-01-01'

The generic example using between is like select.... where <col> BETWEEN 1st value and 2nd value

Because for BETWEEN function 1 the 1st value should be low as it selects the only those values whcih satisfies the criteria value >= 1st Value and value =< 2nd value and then fetches the records

In your case there will no such records will come as it will search for dates where Date >= '2008-02-20' and Date =< '2008-01-01'

Reagrds,
Chandan
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Extract the records with a PD field's... sudhakar84 DFSORT/ICETOOL 11 Mon Apr 02, 2018 7:26 pm
No new posts Merge 2 records sancraig16 SYNCSORT 19 Tue Mar 27, 2018 8:17 pm
No new posts Query to compare 2 values of 1 column... Poha Eater DB2 13 Fri Mar 09, 2018 10:45 am
No new posts Copy set of records based on condition krish.deepu SYNCSORT 2 Thu Mar 08, 2018 11:39 am
No new posts How to replace the below query? pkmurali DB2 12 Tue Feb 27, 2018 9:51 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us