Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date ranges in date list 1

Status
Not open for further replies.

BrianOg

Programmer
Feb 10, 2004
12
GB
Given a range of dates held in a field in a table or generated by a query, e.g.:
10/1/04,11/1/04,12/1/04, 23/1/04, 3/2/04,4,2,04, 8,2,04
How can I write a query to generate:

fldStartGap fldEndGap
13/1/04 22/1/04
24/1/04 2/2/04
5/2/04 7/2/04

Would appreciate anyone's help

Brian
 
Try something like
Code:
Select (A.DateField + 1)      As fldStartGap,

       (MIN(B.DateField) - 1) As fldEndGap

From   tbl As A INNER JOIN tbl As B
       ON B.DateField > A.DateField

GROUP BY A.DateField + 1

HAVING A.DateField + 1 <= MIN(B.DateField) - 1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top