Selasa, 10 Juli 2018

Re: [MS_AccessPros] Query: Make EndDateTime of a record the StartDateTime of next record

 

Thank you very much for the suggestion Duane!

I started with it, then complicated it, then ended up adding a column usind Dsum to get a running total of the production minutes.   Then added the running total to the same starting time and got the end time for each record.

I realized I did not work continuously, but only from 6am to 3:30pm.   Did a couple more things.

First, I compared the starting date/time (using Now()) to see if it between 6 and 3:30.  If it is, that is the starting time.  If not, I test if it is before 6 am and if yes I make it 6am and start from that time.  Otherwise I add a day to current date and make the time 6am (I would start work at 6am the next morning).

The I selected the date is as follows:

StartDateTime: IIf(TimeValue(Now()) Between #6:00:00 AM# And #3:30:00 PM#,Now(),IIf(TimeValue(Now())<=#6:00:00 AM#,CDate(Date$() & " 06:00:00 AM"),CDate(Format(DateAdd("d",1,Now()),"mm/dd/yy") & " 06:00:00 AM")))

Second, I calculated the non working minutes in the day and added those to the production minutes per record.  That gave the entire time it would take to produce and order.  The code used is

EndDateTime: DateAdd("n",Round(([CumMinutos]+(Hour(Now())-6)*60+Minute(Now()))/570-1,0)*930+[CumMinutos],[StartDateTime])

570 is the work minutes, 930 is the non work minutes.

So, there it is.   I am currently running different scenarios to make sure it runs as intended with all my products and conditions.

Maybe one of these days I'll add a calendar to it, instead of assuming I work all days the same time.

But this is good enough for now and very handy query in my business.

Thank you again. 



---In MS_Access_Professionals@yahoogroups.com, <duanehookom@...> wrote :

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@... [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
 


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
ProductDescriptionOrderQtyProductionDateMinutesStartDateTimeEndDateTime
P01Photo Album157/3/2018 120 7/3/2018 6:007/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
ProductDescriptionOrderQtyProductionDateMinutesStartDateTimeEndDateTime
P01Photo Album157/3/2018 120 7/3/2018 6:007/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
ProductDescriptionMinutes
P01Photo Album 24
     
Table Orders
ProductDescriptionOrderQtyProductionDate
P01Photo Album157/3/2018
P01 Photo Album 2 15 7/3/2018
P01 Photo Album 3 10 7/3/2018




__._,_.___

Posted by: lrheimpel@gmail.com
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (6)

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