简体   繁体   English

MS Access-在新表中记录每日查询总数

[英]MS Access - Log daily totals of query in new table

I have an ODBC database that I've linked to an Access table. 我有一个已链接到Access表的ODBC数据库。 I've been using Access to generate some custom queries/reports. 我一直在使用Access生成一些自定义查询/报告。

However, this ODBC database changes frequently and I'm trying to discover where the discrepancy is coming from. 但是,此ODBC数据库经常更改,因此我试图找出差异的来源。 (hundreds of thousands of records to go through, but I can easily filter it down into what I'm concerned about) (数十万条记录要经过,但我可以轻松地将其过滤到我所关注的内容中)

Right now I've been manually pulling the data each day, exporting to Excel, counting the totals for each category I want to track, and logging in another Excel file. 现在,我每天都在手动提取数据,导出到Excel,计算要跟踪的每个类别的总数,并登录另一个Excel文件。

I'd rather automate this in Access if possible, but haven't been able to get my heard around it yet. 如果可能的话,我宁愿在Access中自动执行此操作,但还没有得到我的答复。

I've already linked the ODBC databases I'm concerned with, and can generate the query I want to generate. 我已经链接了我关心的ODBC数据库,并且可以生成我要生成的查询。

What I'm struggling with is how to capture this daily and then log that total so I can trend it over a given time period. 我正在努力的是如何每天捕获此数据,然后记录该总数,以便可以在给定的时间段内对其进行趋势分析。

If it the data was constant, this would be easy for me to understand/do. 如果数据是恒定的,这对我来说很容易理解/做。 However, the data can change daily. 但是,数据可能每天更改。

EX: This is a database of work orders. EX:这是工作单数据库。 Work orders(which are basically my primary key) are assigned to different departments. 工单(基本上是我的主键)分配给不同的部门。 A single work order can belong to many different departments and have multiple tasks/holds/actions tied to it. 单个工作订单可以属于多个不同部门,并​​且具有多个与其相关联的任务/任务/动作。

Work Order 0237153-03 could be assigned to Department A today, but then could be reassigned to Department B tomorrow. 今天可以将工作订单0237153-03分配给A部门,但是明天可以将其重新分配给B部门。

These work orders also have "ranking codes" such as Priority A, B, C. These too can be changed at any given time. 这些工单还具有“等级代码”,例如优先级A,B,C。也可以在任何给定时间更改它们。 Today Work Order 0237153-03 could be priority A, but tomorrow someone may decide that it should actually be Priority B. 今天的工作指令0237153-03可能是优先级A,但是明天有人可能会决定它实际上应该是优先级B。

This is why I want to capture all available data each day (The new work orders that have come in overnight, and all the old work orders that may have had changes made to them), count the totals of the different fields I'm concerned about, then log this data. 这就是为什么我要捕获每天所有可用的数据(过夜产生的新工作订单,以及可能对其进行过更改的所有旧工作订单),计算我所关注的不同字段的总数关于,然后记录此数据。

Then repeat this everyday. 然后每天重复一次。

the question you ask is very vague so here is a general answer. 您提出的问题非常模糊,因此这里是一个一般性的答案。

You are counting the items you get from a database table. 您正在计算从数据库表中获得的项目。

It may be that you don't need to actually count them every day, but if the table in the database stores all the data for every day, you simply need to create a query to count the items that are in the table for every day that is stored in the table. 也许您不需要每天都对它们进行实际计数,但是如果数据库中的表每天存储所有数据,则只需要创建一个查询来对每天表中的项目进行计数存储在表中。

You are right that this would be best done in access. 您说得对,最好在访问中完成。

You might not have the "log the counts in another table" though. 但是,您可能没有“在另一个表中记录计数”。

It seems you are quite new to access so you might benefit form these links videos numbered 61, 70 here and also video 7 here 看来你是很新的接入,所以你可能会受益形式这些链接的视频编号61,70 在这里也视频7 这里

These will help or buy a book / use web resources. 这些将帮助或购买书籍/使用网络资源。

PART2. 第2部分。

If you have to bodge it because you can't get the ODBC database to use triggers/data macros to log a history you could store a history yourself like this.... BUT you have to do it EVERY day. 如果由于无法获取ODBC数据库来使用触发器/数据宏来记录历史记录而不得不对其进行简化,则可以自己存储历史记录...。但是您每天都必须这样做。

0 On day 1 take a full copy of the ODBC data as YOURTABLE. 0在第1天,将ODBC数据的完整副本作为YOURTABLE。 Add a field "dump Number" and set it all to 1. 1. Link to the ODBC data every day. 添加一个字段“转储号”并将其全部设置为1。1.每天链接到ODBC数据。

  1. join from YOURTABLE to the ODBC table and find any records that have changed (ie test just the fields you want to monitor and if any of them have changed...). 从YOURTABLE连接到ODBC表,并找到任何已更改的记录(即仅测试要监视的字段以及是否有任何更改...)。

  2. Append these changed records to YOURTABLE with a new value for "dump number of 2" This MUST always increment! 用“ dump number of 2”的新值将这些更改的记录追加到YOURTABLE。此值必须始终递增!

  3. You can now write SQL to get the most recent record for each primary key. 现在,您可以编写SQL以获得每个主键的最新记录。

      SELECT * FROM Mytable WHERE ( SELECT PrimaryKeyFields, MAX(DumpNumber) AS MAXDumpNumber FROM Mytable GROUP BY PrimaryKeyFields ) AS T1 ON t1.PrimaryKeyFields = Mytable.PrimaryKeyFields AND t1.MAXDumpNumber= Mytable.DumpNumber 
  4. You can compare the most recent records with any previous records. 您可以将最新记录与任何以前的记录进行比较。 ie to get the previous dump Note that this will NOT work in the abvoe SQL (unless you always keep every record!) 即获取先前的转储请注意,这在abvoe SQL中将不起作用(除非您始终保留每条记录!)

     AND t1.MAXDumpNumber-1 = Mytable.DumpNumber 

    Use something like this to get the previous row: 使用类似这样的东西来获取上一行:

      SELECT * FROM Mytable INNER JOIN ( SELECT PrimaryKeyFields , MAX(DumpNumber) AS MAXDumpNumber FROM Mytable INNER JOIN ( SELECT PrimaryKeyFields , MAX(DumpNumber) AS MAXDumpNumber FROM Mytable GROUP BY PrimaryKeyFields ) AS TabLatest ON TabLatest.PrimaryKeyFields = Mytable.PrimaryKeyFields AND TabLatest.MAXDumpNumber <> Mytable.DumpNumber -- Note that the <> is VERY important GROUP BY PrimaryKeyFields ) AS T1 ON t1.PrimaryKeyFields = Mytable.PrimaryKeyFields AND t1.MAXDumpNumber= Mytable.DumpNumber 
  5. Create 4 and 5 and MS Access named queries (or SS views) and then treate them like tables to do comparison. 创建4和5以及MS Access命名查询(或SS视图),然后将它们像表一样进行比较。

Make sure you have indexes created on the PK fields and the DumpNumber and they shoudl be unique - this will speed things up.... 确保您在PK字段和DumpNumber上创建了索引,并且它们应该是唯一的-这样可以加快速度。

  1. Finish it in time for christmas... and flag this as an answer! 在圣诞节前及时完成...并将其标记为答案!

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

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