简体   繁体   English

修改查询记录集以完成信息 (MS Access)

[英]Modify a query recordset to complete information (MS Access)

im working in a project in Microsoft access to query the date, hour and a quantity of products by line of production.我在微软的一个项目中工作,可以按生产线查询日期、时间和产品数量。 However, I need to display all of the 24 hours of production in a column but cannot do it since I don't have records for the missing hours.但是,我需要在列中显示所有 24 小时的生产时间,但不能这样做,因为我没有丢失时间的记录。 I'm using Totals to sum the quantity of products produced.我正在使用 Totals 来总结生产的产品数量。

Is there a way to add the missing hours to my query if I lack of records?如果我缺少记录,有没有办法将缺少的时间添加到我的查询中? Or maybe doing it another way?或者也许以另一种方式做?

I have tried making a table with the hours (Table: Horas) of the day and making a relationship to display all hours and left in blank the other missing fields.我尝试用一​​天中的小时数(表:Horas)制作一个表格,并建立一个关系来显示所有小时数,并将其他缺失的字段留空。 It didn't work它没有用

This is my query:这是我的查询:

SELECT Consulta.[Date Epei], Horas.Hora, Consulta.Hr, Sum(Consulta.Racks) AS Actual, 
IIf(Weekday([Date Epei])=6 And [Hr] Between 5 And 18,0,
IIf(Weekday([Date Epei])=7 And [Hr] Between 4 And 20,0,
IIf(Weekday([Date Epei])=1,0,-Int(-[Ln100]/24)))) AS Plan,
([Actual]/[Plan])*100 AS [Cumplimiento(%)]
FROM Horas 
LEFT JOIN ([Plan Lineas] 
RIGHT JOIN Consulta ON [Plan Lineas].Dia = Consulta.[Date Epei]) ON Horas.Hora = Consulta.Hr
WHERE (((Consulta.Line)="Linea 100"))
GROUP BY Consulta.[Date Epei], Horas.Hora, Consulta.Hr, 
IIf(Weekday([Date Epei])=6 And [Hr] Between 5 And 18,0,
IIf(Weekday([Date Epei])=7 And [Hr] Between 4 And 20,0,
IIf(Weekday([Date Epei])=1,0,-Int(-[Ln100]/24))));

The If statements will change the [Plan Lineas] field to a value of 0 if it's Friday between 5 and 6pm, Saturday between 4 and 8pm or Sunday.如果周五下午 5 点到 6 点之间、周六下午 4 点到 8 点之间或周日,则 If 语句会将 [Plan Lineas] 字段更改为 0 值。 (I know it's messy, and will try to reduce it in the future). (我知道它很乱,将来会尝试减少它)。

"Consulta" is a query where I made some calculated fields from various tables. “Consulta”是一个查询,我从各种表中创建了一些计算字段。

This is my first time using Access, and started looking if there's a way using VBA,.这是我第一次使用 Access,并开始寻找是否有使用 VBA 的方法。 So any help or guidance I will appreciate it.所以任何帮助或指导我都会很感激。

You can join to a derived table of totals for 24 hours.您可以加入 24 小时内的总计派生表。

Beware DST shifts in the times of shift changes!在换班时要注意夏令时的变化!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM