Here is the SQL with the Start Date column. I had to use Nz()
SELECT Orders.Product, Orders.Description, Orders.Order, Orders.Qty, [Qty]*[Minutes] AS TotalMinutes,
(SELECT MIN(ProductionDate) FROM Orders)+Nz((SELECT Sum(P.Minutes * O.Qty) FROM Orders O INNER JOIN Products P ON O.Product = P.Product WHERE O.Order <Orders.Order)/(24*60),0) AS StartDate,
(SELECT MIN(ProductionDate) FROM Orders)+(SELECT Sum(P.Minutes * O.Qty) FROM Orders O INNER JOIN Products P ON O.Product = P.Product WHERE O.Order <=Orders.Order)/(24*60) AS EndDate
FROM Orders INNER JOIN Products ON Orders.Product = Products.Product
ORDER BY Orders.Order;
Duane
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of lrheimpel@gmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Monday, July 2, 2018 9:25 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query: Make EndDateTime of a record the StartDateTime of next record
Sent: Monday, July 2, 2018 9:25 AM
To: MS_Access_Professionals@yahoogroups.com
Subject: Re: [MS_AccessPros] Query: Make EndDateTime of a record the StartDateTime of next record
Duane,
Here is a simplified version to make it easier to see.
Tables are linked by column product. Minutes are calculated by multiplying Product Table minutes of product times order qty.
Date format I use is mm/dd/yyyy if that makes a difference.
Current Output | |||||||
Product | Description | Order | Qty | ProductionDate | Minutes | StartDateTime | EndDateTime |
P01 | Photo Album | 1 | 5 | 7/3/2018 | 120 | 7/3/2018 6:00 | 7/3/18 8:00 |
P01 | Photo Album | 2 | 15 | 7/3/2018 | 145 | 7/3/2018 6:00 | 7/3/18 8:25 |
P01 | Photo Album | 3 | 10 | 7/3/2018 | 36 | 7/3/2018 6:00 | 7/3/18 6:36 |
Desired Output | |||||||
Product | Description | Order | Qty | ProductionDate | Minutes | StartDateTime | EndDateTime |
P01 | Photo Album | 1 | 5 | 7/3/2018 | 120 | 7/3/2018 6:00 | 7/3/18 8:00 |
P01 | Photo Album | 2 | 15 | 7/3/2018 | 360 | 7/3/2018 8:00 | 7/3/18 14:00 |
P01 | Photo Album | 3 | 10 | 7/3/2018 | 240 | 7/3/2018 14:00 | 7/3/18 18:00 |
Table Products | |||||||
Product | Description | Minutes | |||||
P01 | Photo Album | 24 | |||||
Table Orders | |||||||
Product | Description | Order | Qty | ProductionDate | |||
P01 | Photo Album | 1 | 5 | 7/3/2018 | |||
P01 | Photo Album | 2 | 15 | 7/3/2018 | |||
P01 | Photo Album | 3 | 10 | 7/3/2018 |
__._,_.___
Posted by: Duane Hookom <duanehookom@hotmail.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (5) |
Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.
SPONSORED LINKS
.
__,_._,___
Tidak ada komentar:
Posting Komentar