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: 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 Format Last Record differently from r... Learncoholic DFSORT/ICETOOL 0 Tue Oct 24, 2017 12:01 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts HEX value search in a DB2 query maxsubrat DB2 2 Wed Oct 04, 2017 3:04 pm
No new posts Addition of two records on 2 fields amar143 SYNCSORT 8 Tue Oct 03, 2017 11:14 am
No new posts Create procedure issues -628 when add... chandraBE DB2 1 Mon Sep 18, 2017 12:16 pm

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