Assuming tblTest with field [ie].
Create query "qselStart" with the sql:
SELECT tblTest.ie
FROM tblTest
WHERE (Select Count(*) from tblTest t WHERE t.ie+1 = tblTest.ie)=0;
Then create a query "qselRanges" with sql of:
SELECT qselStart.ie,
(Select Max(ie)
FROM tblTest t where t.ie<
(Select Min(ie)
from qselStart q where q.ie> qselStart.ie)) AS [To]
FROM qselStart;
You can then create a query that concatentates the two fields together.
Because Access doesn't support derived tables such as
Select a,b,c From (Select * From tbl Where ...)
You need to do this in two steps. First define a query like this
SELECT A.Num AS First, B.Num AS Second
FROM tbl AS A, tbl AS B
WHERE A.Num <= B.Num
AND NOT EXISTS (Select * From tbl As X Where X.Num = B.Num + 1)
AND NOT EXISTS (Select * From tbl As X Where X.Num = A.Num - 1);
And Save it as "Ranges"
Then define another query based on that one like this
SELECT A.First AS StartRange, MIN(A.Second) AS EndRange, (A.First & "-" & MIN(A.Second)) As [Range]
FROM Ranges AS A
GROUP BY A.First;
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.