I have been given the task of finding out which of our customers have not bought from us in 6 months and have no outstanding sales orders.
The information is contained in two tables: customers and sales
The customer number is common to both tables and I need to pull the customer number and name the customer table has a invoice date so i could look for that and the sales table has a status column that includes closed and open status's and a date printed column.
I am sure this is all I would need to put it together but am stumped as to how.
I know I would write something like.
Select Distinct I.Customer,
I.InvoiceToName
From
tblarInvoice I
Inner Join tblsoSO S
On I.CustomerShipTo = S.CustomerShipTo
Where max(I.dateprinted) <= '06/01/2013'
or max(S.dateordered) <= '06/01/2013'
and S.status = 'closed'
I am using S.status for a customer that placed a blanket order that could go back as much as a year. If S.status is open then I do not want to include the customer in the result set.
the above would not work as I think I would get every record back to the beginning of time and I just need those that have not ordered in the last 6 months. not to mention the problem with an aggregate in the Where statement. Which I know does not work but do not know how to make work even if it was what I wanted.
So I am stumped as to what to use to get the no orders for 6 months back.
The information is contained in two tables: customers and sales
The customer number is common to both tables and I need to pull the customer number and name the customer table has a invoice date so i could look for that and the sales table has a status column that includes closed and open status's and a date printed column.
I am sure this is all I would need to put it together but am stumped as to how.
I know I would write something like.
Select Distinct I.Customer,
I.InvoiceToName
From
tblarInvoice I
Inner Join tblsoSO S
On I.CustomerShipTo = S.CustomerShipTo
Where max(I.dateprinted) <= '06/01/2013'
or max(S.dateordered) <= '06/01/2013'
and S.status = 'closed'
I am using S.status for a customer that placed a blanket order that could go back as much as a year. If S.status is open then I do not want to include the customer in the result set.
the above would not work as I think I would get every record back to the beginning of time and I just need those that have not ordered in the last 6 months. not to mention the problem with an aggregate in the Where statement. Which I know does not work but do not know how to make work even if it was what I wanted.
So I am stumped as to what to use to get the no orders for 6 months back.