Finding records with no entry within past year

  • Thread starter bg17067 via AccessMonster.com
  • Start date
B

bg17067 via AccessMonster.com

I have two tables [Tbl_Customers] and [Tbl_Orders] these are linked by
[CustID]. When orders are entered into [Tbl_Orders] a [Date of Order] field
is populated with current date.

I am trying to write a query that will show what customers have not placed an
order within the past 365 days. I have an expression that will show orders
within a year {Between Date() And (Date()-365)} but that's as far as I can
take it.

Thanks,
 
B

bg17067 via AccessMonster.com

Allen,

Worked like a charm! Thank you for the quick reply.

Allen said:
See:
Subquery basics: Identifying what is NOT there
at:
http://allenbrowne.com/subquery-01.html

The first example is close to what you need.
I have two tables [Tbl_Customers] and [Tbl_Orders] these are linked by
[CustID]. When orders are entered into [Tbl_Orders] a [Date of Order]
[quoted text clipped - 7 lines]
within a year {Between Date() And (Date()-365)} but that's as far as I can
take it
 
B

bg17067 via AccessMonster.com

Is there a way to show the last [Date of Order] with this subquery?

SELECT Tbl_Customers.AccountNumber, Tbl_Customers.Name
FROM Tbl_Customers
WHERE NOT EXISTS
(SELECT Tbl_Orders.[Order #]
FROM Tbl_Orders
WHERE Tbl_Orders.AccountNumber = Tbl_Customers.AccountNumber
AND Tbl_Orders.[Date of Order] > Date() - 365);


I've looked at the examples on the website but haven't figured out how to tie
two subqueries together.

Thanks,
Brian
See:
Subquery basics: Identifying what is NOT there
[quoted text clipped - 8 lines]
 
A

Allen Browne

See:
http://www.mvps.org/access/queries/qry0020.htm

Michel Walsh discusses 4 approaches.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

bg17067 via AccessMonster.com said:
Is there a way to show the last [Date of Order] with this subquery?

SELECT Tbl_Customers.AccountNumber, Tbl_Customers.Name
FROM Tbl_Customers
WHERE NOT EXISTS
(SELECT Tbl_Orders.[Order #]
FROM Tbl_Orders
WHERE Tbl_Orders.AccountNumber = Tbl_Customers.AccountNumber
AND Tbl_Orders.[Date of Order] > Date() - 365);


I've looked at the examples on the website but haven't figured out how
to tie two subqueries together.

Thanks,
Brian
See:
Subquery basics: Identifying what is NOT there
[quoted text clipped - 8 lines]
within a year {Between Date() And (Date()-365)} but that's as far
as I can take it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

DMAX function in query 1
Excel Vba to change displayed year automatically. 14
making age group query work 7
age groups 6
select records for past year 3
Criteria Help 5
Year to date month/year 1
no recent records query 4

Top