S is an alias of tblInv > 'tblinv AS S'
as is E > 'tblinv AS E'
S is also an alias for a query (sorry, could have given it a different letter)
Code:
(SELECT S.invdate, S.[invnum], S.[invnum]-1 AS MissingTo
FROM tblinv AS S LEFT JOIN tblinv AS E ON (S.invdate = E.invdate) AND (S.[invnum]-1=E.[invnum])
WHERE (((E.[invnum]) Is Null))) AS S
And M is an alias for another query
Code:
(SELECT S.invdate, S.[invnum], Max(tblinv.[invnum]+1) AS MissingFrom, S.MissingTo
FROM tblinv INNER JOIN (SELECT S.invdate, S.[invnum], S.[invnum]-1 AS MissingTo FROM tblinv AS S LEFT JOIN tblinv AS E ON (S.invdate = E.invdate) AND (S.[invnum]-1=E.[invnum]) WHERE (((E.[invnum]) Is Null))) AS S ON tblinv.invdate=S.invdate
WHERE (((tblinv.[invnum])<[MissingTo]))
GROUP BY S.invdate, S.[invnum], S.MissingTo) AS M
you can write these other queries as separate queries if you wish and then combine into 1 query
And I use alias's to reduce the amount of typing and to indicated what the alias is about
S=Start
E=End
M=Missing
(it works for me
)
I have the code as a broad template query for this sort of scenario which can be used in many tables just by making a few simple changes. So if this was for say identifying missing employee hours I might change tblInv to tblEmpTimes, invnum to startTime and invDate to ClockDate- the alias's stay the same