[英]ms access query (ms access freezes)
I have this report and need to add totals for each person (the red circle) existing report我有这份报告,需要为每个人(红色圆圈)现有报告添加总数
I cannot change the existing report so I export data from MS SQL to MS Access and create a new report there.我无法更改现有报告,因此我将数据从 MS SQL 导出到 MS Access 并在那里创建新报告。 I got it working for one employee but have trouble with a query which would for multiple employees.我让它为一名员工工作,但在查询多名员工时遇到了麻烦。
This query extract data use as input:此查询提取数据用作输入:
SELECT [TIME].[RCD_NUM], [TIME].[EMP_ID], [TIME].[PPERIOD], [TIME].[PRUN], [TIME].[TDATE], [TIME].[PC], [TIME].[RATE], [TIME].[HOURS], [TIME].[AMOUNT], [TIME].[JOB_ID], [TIME].[UPDATED], [TIME].[UPDATED_BY], [TIME].[LOG_DATE], [TIME].[ORIGINAL_REC_NUM]
FROM [TIME]
WHERE ((([TIME].[EMP_ID])=376) And (([TIME].[TDATE])<=#12/31/2006# And ([TIME].[TDATE])>=#1/1/2006#) And (([TIME].[PC])<599));
this query populates the report:此查询填充报告:
SELECT *
FROM TIME1
WHERE RCD_NUM = (SELECT Max(RCD_NUM) FROM [TIME1] UQ WHERE UQ.PPERIOD = [TIME1].PPERIOD AND UQ.PC = [TIME1].PC);
the problem is if I remove EMP_ID from the first query like this问题是如果我从这样的第一个查询中删除 EMP_ID
SELECT [TIME].[RCD_NUM], [TIME].[EMP_ID], [TIME].[PPERIOD], [TIME].[PRUN], [TIME].[TDATE], [TIME].[PC], [TIME].[RATE], [TIME].[HOURS], [TIME].[AMOUNT], [TIME].[JOB_ID], [TIME].[UPDATED], [TIME].[UPDATED_BY], [TIME].[LOG_DATE], [TIME].[ORIGINAL_REC_NUM]
FROM [TIME]
WHERE ((([TIME].[TDATE])<=#12/31/2006# And ([TIME].[TDATE])>=#1/1/2006#) And (([TIME].[PC])<599));
then the second query doesn't work and ms access freezes when running this query.然后第二个查询不起作用,并且运行此查询时 ms 访问冻结。
any help/idea please?请问有什么帮助/想法吗?
Caveat : I won't pretend to know the precise cause of the problem, but I have had to repeatedly refactor queries in Access to get them working even though the original SQL statements are completely valid in regards to syntax and logic.警告:我不会假装知道问题的确切原因,但我不得不反复重构 Access 中的查询以使它们工作,即使原始 SQL 语句在语法和逻辑方面完全有效。 Sometimes I've had to convolute a sequence of queries just to avoid bugs in Access.有时,为了避免 Access 中的错误,我不得不对一系列查询进行卷积。 Access is often rather dumb and will simply (re)execute queries and subqueries exactly as given without optimization. Access 通常是相当愚蠢的,并且会简单地(重新)执行完全按照给定的查询和子查询,而无需优化。 At other times Access will attempt to combine queries by performing some internal optimizations, but sometimes those introduce frustrating bugs.在其他时候,Access 会尝试通过执行一些内部优化来组合查询,但有时这些会引入令人沮丧的错误。 Something as simple as a name change or column reordering can be the difference between a functioning query and one that crashes or freezes Access.像名称更改或列重新排序这样简单的事情可能是正常运行的查询与崩溃或冻结 Access 的查询之间的区别。
First consider:首先考虑:
[EMP_ID]
selects a small subset, but the full table is large enough to "freeze" Access.也许这只是一个性能问题,其中通过[EMP_ID]
限制集合选择了一个小的子集,但整个表足够大以“冻结”访问。
Other hints:其他提示:
Try refactoring the "second" query by performing a join in the FROM clause rather than the WHERE clause.尝试通过在 FROM 子句而不是 WHERE 子句中执行连接来重构“第二个”查询。 In doing this, you may also want to save the subquery as a named query (just as [TIME1]
is saved).这样做时,您可能还想将子查询保存为命名查询(就像保存[TIME1]
)。 Whether or not a query is saved or embedded in another statement CAN change the behavior of Access (see caveat) even though the results should be identical.查询是否被保存或嵌入到另一个语句中都可以改变 Access 的行为(见警告),即使结果应该是相同的。
Here's a version with the embedded aggregate query.这是一个带有嵌入式聚合查询的版本。 Notice how all column references are qualified with the source.请注意所有列引用如何使用源进行限定。 Some of the original query's columns do not have a source alias prefixing the column name.某些原始查询的列在列名前没有源别名。 Remember the caveat... such picky details can affect Access behavior.:记住警告...这样挑剔的细节会影响访问行为。:
SELECT TIME1.*
FROM TIME1 INNER JOIN
(SELECT UQ.PPERIOD, UQ.PC, Max(UQ.RCD_NUM) As Max_RCD_NUM
FROM [TIME1] UQ
GROUP BY UQ.PPERIOD, UQ.PC) As TIMEAGG
ON (TIME1.PPERIOD = TIMEAGG.PPERIOD) And (TIME1.PC = TIMEAGG.PC)
AND (TIME1.RCD_NUM = TIMEAGG.Max_RCD_NUM)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.