Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups 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: 269
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 Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts JCL to Set Return code based on DB2 S... vinu78 DB2 17 Mon Mar 13, 2017 9:47 pm
No new posts Join giving more records than expected Danielle.Filteau SYNCSORT 2 Thu Mar 09, 2017 3:28 am
No new posts TSO or command line utility to genera... kishpra JCL & VSAM 3 Thu Mar 09, 2017 1:11 am
No new posts Extract set of records matching on ac... bhaskar_kanteti DFSORT/ICETOOL 3 Mon Mar 06, 2017 7:19 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us