Kevin Smith
asked on
I need to get a list of what products a customer has in our inventory but hasn't ordered in a certain amount of time
We provide parts to customers. Sometimes we keep parts in stock and ship them to them when they need them. I need to be able to ask my database what parts might be in stock for a particular customer that they haven't ordered in the past year (or whatever date). I have a table with my parts. I have a table with orders for those parts. How do I write my query so that I can tell it my customer, tell it the past year, and then it return all the parts that are in inventory that they haven't ordered in the amount of time I ask for?
ASKER
It looks like this will just pick up something that was ordered before the selected date. I would need it to show only parts ordered that they haven't ordered in the past while. So if they had three parts (with one still in inventory), parta, partb and partc. They ordered parta, partb and partc over the past year, bu they ordered partb last month. If I put in 6/1/2015, I would want it to return parta and partc, but not partb.
Basically, I need it to compare all the parts for that customer against the orders for the past (insert date), and return ONLY the parts they haven't ordered since then.
Basically, I need it to compare all the parts for that customer against the orders for the past (insert date), and return ONLY the parts they haven't ordered since then.
Then this might be a more complicated that your original question indicated...
Like mankowitz, I can get you a query that lists all the parts ordered and show the approximate time since they were last ordered.
(see the attached sample)
Do you need the answer here to be in the form of a "Complete Solution" or do you just need help with the query?
Your question is not very specific, so it is not clear how you will be specifying the Customer, the time frame, or how you are comparing the results to your existing inventory levels
For example, how are you defining a "Year"
365 days from the last OrderDate
Or
Last Year (anything in 2014)
The same type of confusing will arise with terms like Weeks or Months.
To be on the safe side, you should simply specify the "days"
You can always create a system to translate the days into whatever date interval format you need.
(A translation table perhaps, or use a function)
You also, still have not posted your deign details, so again, it will be a lot more difficult to form a specifc "answer" here.
Here is a quick sample that lists the days since the last Order and "roughly" translates the days into Weeks, Months and years.
How this will intergrate this into your "inventory" system, may need to be an entirely different question/thread
JeffCoachman
Database114.mdb
Like mankowitz, I can get you a query that lists all the parts ordered and show the approximate time since they were last ordered.
(see the attached sample)
Do you need the answer here to be in the form of a "Complete Solution" or do you just need help with the query?
Your question is not very specific, so it is not clear how you will be specifying the Customer, the time frame, or how you are comparing the results to your existing inventory levels
For example, how are you defining a "Year"
365 days from the last OrderDate
Or
Last Year (anything in 2014)
The same type of confusing will arise with terms like Weeks or Months.
To be on the safe side, you should simply specify the "days"
You can always create a system to translate the days into whatever date interval format you need.
(A translation table perhaps, or use a function)
You also, still have not posted your deign details, so again, it will be a lot more difficult to form a specifc "answer" here.
Here is a quick sample that lists the days since the last Order and "roughly" translates the days into Weeks, Months and years.
How this will intergrate this into your "inventory" system, may need to be an entirely different question/thread
JeffCoachman
Database114.mdb
I would have to test with some actual data, but the subselect
(SELECT max(orderdate) from orders where partnumber=p.partnumber)
should return null for cases where the person didn't buy anything, and a null comparison should be false. If not, you could replace it with
(SELECT count(*) from orders where partnumber=p.partnumber) > 1 AND (SELECT max(orderdate) from orders where partnumber=p.partnumber)
(SELECT max(orderdate) from orders where partnumber=p.partnumber)
should return null for cases where the person didn't buy anything, and a null comparison should be false. If not, you could replace it with
(SELECT count(*) from orders where partnumber=p.partnumber) > 1 AND (SELECT max(orderdate) from orders where partnumber=p.partnumber)
Perhaps mankowitz has a better handle on this,
I will step aside now to avoid confusion.
I will step aside now to avoid confusion.
ASKER
Okay, there is very limited data in this, but I threw in some newer and older dates and a part number or two that should give a difference. Either way, here's what I need it to do.
Orders shows the customer along with the order. The OrderDet lists all parts on a particular order, as well as the DueDate for that part.
Estim shows all parts, the QtyOnHand, and the customer.
I will have a form that lets me pick a customer and put in a date to show any parts that were not ordered after that date. So if I put in SFI and 9/21/2014, I want it to look at the SFI parts on the Estim table and say "hey, here's all the parts you have in inventory SFI...here's the parts you haven't ordered since 9/21/2014." (not literally say it of course, just to return those results. Basically, it'll look at everything after 9/21/2014, then check the Estim table to see what hasn't been ordered.
I know how to do the forms and searches and all of that, so don't worry about that stuff.
Orders shows the customer along with the order. The OrderDet lists all parts on a particular order, as well as the DueDate for that part.
Estim shows all parts, the QtyOnHand, and the customer.
I will have a form that lets me pick a customer and put in a date to show any parts that were not ordered after that date. So if I put in SFI and 9/21/2014, I want it to look at the SFI parts on the Estim table and say "hey, here's all the parts you have in inventory SFI...here's the parts you haven't ordered since 9/21/2014." (not literally say it of course, just to return those results. Basically, it'll look at everything after 9/21/2014, then check the Estim table to see what hasn't been ordered.
I know how to do the forms and searches and all of that, so don't worry about that stuff.
ASKER
Forgot to attach the file...
Database5.accdb
Database5.accdb
can you check the tables? The part numbers in estim don't correlate to the part numbers in the other tables.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SELECT * from
parts p join orders o on (p.partnumber = o.partnumber)
join customers c on (o.customernumber = c.customernumber)
WHERE
p.inventory > 1
AND
(SELECT max(orderdate) from orders where partnumber=p.partnumber) < DateAdd("yyyy", -1, Date())