简体   繁体   English

从Excel查询访问:可变参数

[英]Query Access from Excel: Variable Parameters

I've been doing in depth, functional area dashboards in excel that are refreshed upon end-user command of the 'refresh all' button. 我一直在深入研究excel中的功能区仪表板,这些仪表板是根据最终用户“刷新全部”按钮的命令进行刷新的。 The only problem I am running into is refreshing daily production when it is past midnight, thus turning access' back end query of 'date()' to, well, the current day at midnight. 我遇到的唯一问题是在午夜过后刷新每日生产,从而将“ date()”的访问后端查询变成当前午夜的当前日期。

This has been the condition I want to work properly: I want everything >= 5 AM for either today or previous day based on the NOW time. 这是我要正常工作的条件:我希望根据现在的时间,今天或前一天的所有> = 5 AM。

WHERE start_time >=
   (iif(timevalue(now()) between #00:00# and #4:59#,date()-1,date()))
AND timevalue(start_time) >= #5:00#;

The thing is that it is returning in such an extremely slow rate. 问题是它以极慢的速度返回。

I don't think I've ever waited for it to complete. 我认为我从未等待它完成。 I'm not sure if its calculating this logic on every record involved in the back end table or not, which would explain the lock up. 我不确定它是否在后端表中涉及的每个记录上计算此逻辑,这将解释锁定。

I really want to avoid building any logic dynamically as I am simply using Excel to call upon this Access query through the query wizard. 我真的想避免动态地构建任何逻辑,因为我只是使用Excel通过查询向导来调用此Access查询。 I would hate to have to resort to an access button triggering a module to build the query dynamically and then focus the excel window and refresh. 我讨厌不得不诉诸访问按钮来触发模块以动态构建查询,然后将Excel窗口聚焦并刷新。

It would be nice to create an object on, say, a [Form]! 最好在[Form]上创建一个对象! but that is only useful when the form is active.. even then the SQL rejects any sub-calculations within the object of the form. 但这仅在表单处于活动状态时才有用。即使这样,SQL也会拒绝表单对象内的任何子计算。

Any thoughts? 有什么想法吗?

I believe parsing down to the mathematical equivalent of a boolean HOUR(Now)<5 should speed things up considerably. 我认为将其解析为布尔HOUR(Now)<5的数学等价物应该可以大大加快速度。

WHERE start_time >= (Date + (Hour(Now)<5) + TimeSerial(5, 0, 0))

A boolean True is considered -1. 布尔 True被认为是-1。

You can use: 您可以使用:

WHERE start_time 
    (Between Date() - 1 + #05:00:00# And Date() - 1 + #23:59:59#) 
    Or 
    (Between Date() + #05:00:00# And Date() + #23:59:59#)

This seems to be working; 这似乎有效; I needed a ' ' to concat times correctly. 我需要一个''来正确地计时。 Gustav brought up the 'between' and 'or'; 古斯塔夫提出了“之间”和“或”之间的关系。 this is working fine on my offline test db - I will mark this way down as a possible solution. 这在我的离线测试数据库上工作正常-我将这种方式标记为可能的解决方案。 I also added seconds in order to capture last minute data of 23:59:00 to 23:59:59 我还添加了几秒钟,以捕获23:59:00至23:59:59的最新数据

        WHERE 

iif(timevalue(now()) Between #00:00# And #4:59#,
(start_time 
 Between Date()-1&' '&#05:00# And Date()-1&' '&#23:59:59#)

  OR

(start_time Between date()&' '&#00:00# And date()&' '&#23.59:59#),

(start_time Between date()&' '&#00:00# And date()&' '&#23.59:59#));

I just now need to build into it the now() condition in an iif statement to decided which condition to exectute! 我现在只需要在iif语句中将now()条件构建到其中,以决定执行哪个条件!

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

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