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
 

 

Missing dates in date range

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

New User


Joined: 05 Dec 2007
Posts: 82
Location: chennai

PostPosted: Fri Oct 30, 2009 4:43 pm    Post subject: Missing dates in date range
Reply with quote

Hi,
My requirement is to find out the missing dates in table like

Name Start-date End-date
Name1 1 5
Name1 8 20
Name1 22 31

Assuming the above table has attendance details, Name1 has attended classes from 1 to 5, 8 to 20 and 22 till 31st.
The missing dates(absent) are 6,7,21 which i need to capture using a query.
Please advise.

Thanks,
Anand
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6967
Location: porcelain throne

PostPosted: Fri Oct 30, 2009 5:34 pm    Post subject:
Reply with quote

ask one of your classmates.

use the forum search; this question was asked by the last class.
Back to top
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Fri Oct 30, 2009 7:36 pm    Post subject:
Reply with quote

did a search : didn't find it.(this doesn't mean it's not there, just that i can't find properly)

generating a CTE table containing dates (or a sequence of numbers ) is not that hard with recursive SQL
then a simple not exists should give you a result.
Code:
With allnumber(nbr) as (
   select 1 from sysibm.sysdummy1
union all
   select nbr + 1 from allnumbers where nbr < 99)

Select name1 , nbr from  allnumbers N, table1 A
where not exists (select * from table1 B where A.name1 = B.name1 and B.nfrom <= N.nbr and B.nto >= N.nbr)


If there are no overlaps , following query (without recursive sql) will give you also a workable result :

Code:
select * from
 ( select name1, 'from'  , nto + 1 from table1 t1
   where nto < :max_nto
     and not exists (select * from table1 t2 where t1.name1 = t2.name1 and t2.nfr = (t1.nto +1))
 )  tos_without_from
union all
 ( select name1, 'to  ', nfr - 1 from table1 t1
   where nfr > :min_nfr
     and not exists (select * from table1 t2 where t1.name1 = t2.name1 and t2.nto = (t1.nfr - 1))
 ) froms_without_to
where tos_without_from.name1 = froms_without_to.name1
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 Validate date and numeric fields and ... Rick Silvers DFSORT/ICETOOL 6 Thu May 11, 2017 6:51 pm
No new posts Cobol upgrade - source code missing f... gthmrj IBM Tools 1 Wed Apr 26, 2017 6:04 pm
No new posts LISTIDR compiled date/time jerryte IBM Tools 3 Thu Apr 20, 2017 7:37 pm
No new posts SUBSTR for Date functions Shaheen Shaik DB2 4 Thu Apr 06, 2017 2:14 pm
No new posts Date and time format in CICS Chandru3183 CICS 2 Sat Mar 18, 2017 12:46 pm


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