SQL 通过经典 ADO - 未定义函数“Round”?
我正在开发一个遗留产品,并且我有一些通过 ADO 执行到 Access 数据库的 SQL,其中包含与 SQL Server 的链接表。 当我执行 SQL 时,我收到错误“未定义函数‘Round’”,但如果我接受查询并直接在 Access 中运行,则可以正常工作。 我知道一切都是正确的,这是一个特定于机器的问题,因为这是生产代码,它可以在其他机器上运行,并且已成功部署到许多客户端。
说实话,我什至不知道从哪里开始。 我正在运行正确(最新)版本的 Jet/ADO/MDAC。
任何帮助,将不胜感激。
提前致谢。
编辑:显然,SQL 包含聚合函数“Round”。 我知道 Jet 和 SQL 实现之间的差异。 这个问题是由于我的机器上的组件出现问题而不是代码引起的。 通过 MS Access 2007 但不能通过 ADO 执行时,SQL 可以正确执行。
I'm working on a legacy product and i have some SQL being executed through ADO, to an Access database with linked tables to SQL Server. I'm getting the error 'Undefined function 'Round' when i execute the SQL but if i take the query and run directly in Access it works fine. I know that EVERYTHING is correct and that this is a machine specific issue since this is production code, it works on other machines and has been deployed successfully for many clients.
I'm not even sure where to begin to be honest. I'm running the correct (latest) versions of Jet/ADO/MDAC.
ANY help would be appreciated.
Thanks in advance.
EDIT: Obviously, the SQL includes the aggregate function 'Round'. I'm aware of the differences between Jet and SQL implementations. This problem is due to some problem with a component on my machine and NOT with the code. The SQL executes properly when done through MS Access 2007 but NOT through ADO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
EDIT2:评论中的正确解决方案:
shahkalpesh:如果它通过 Access 执行良好,则可能是 Access 具有可用的 DLL,该 DLL 具有 Round 函数。 您使用的连接字符串是什么?
Stimul8d:我不知道它怎么能是这样,所以用连接字符串来做。 此代码适用于所有其他机器,无需任何更改; 只是不在我的身上。
安多玛:嗯,这就是你的问题,你的机器坏了。 您仍然可以安装 vb6 sp6也许吧。
Stimul8d:嗯,SP6 修复了它。 干杯 Anndomar,不知道为什么 SP6 修复了它,但它确实修复了!
编辑:根据您的评论
后来又发了两篇文章:
旧答案在这里:
尝试 FLOOR() 而不是 ROUND()。
要将某些内容四舍五入到最接近的整数,您可以:
PS 也许发布您得到的确切错误。 如果是“The round function require 2 to 3 arguments.”,则意味着 Sql Server 正在 ROUND() 上运行。
EDIT2: Right solution from the comments:
shahkalpesh: If it executes fine thru Access, it could be that Access has the DLL available to it, which has the Round function. What is the connection string, you are using?
Stimul8d: I'm not sure how it can be anything so do with the connection string. This code works on EVERY other machine, with no changes; just not on mine.
Andomar: Well, that's your problem right there, your machine is farked up. You can still install vb6 sp6 maybe.
Stimul8d: Well, SP6 fixed it. Cheers Anndomar, no idea why SP6 fixed it but it did!
EDIT: Based on your comment this newsgroup post might be the answer:
And two posts later:
Old answer here:
Try FLOOR() instead of ROUND().
To round something to the nearest integer, you could:
P.S. Maybe post the exact error you get. If it's "The round function requires 2 to 3 arguments.", that means Sql Server is borking on the ROUND().
SQL Server 中也存在 round() 函数。
唯一的区别是:在 Access 中,精度是一个可选参数,但在 SQL Server 中,您必须指定它。
因此,这仅适用于 Access,但不适用于 SQL Server:
这适用于 Access 和 SQL Server:
The round() function exists in SQL Server as well.
The only difference is: in Access the precision is an optional parameter, but in SQL Server you have to specify it.
So this will only work in Access, but not in SQL Server:
This will work in Access and SQL Server:
ACE/Jet 通过 VBA 使用共享表达式服务。 概括地说,ACE/Jet 支持所有其参数和返回值是标量类型(例如,没有数组、没有对象)的 VBA5 函数(与方法不同)作为表达式。
Round()
表达式属于此定义,并且确实可用于 ACE/Jet,其语义与其等效的 VBA 函数相同。 不过,熟悉 ACE/Jet 引擎的人都应该知道,语义可能与 VBA 等效项不同,例如 ACE/Jet ANSI-92 查询模式 SQL返回“Long”,而 VBA
返回“Integer”。
换句话说,
Round()
不会成为这里的问题。ACE/Jet uses share expression services with VBA. Broadly speaking, ACE/Jet supports as expressions all VBA5 functions (as distinct from methods) whose arguments and return values are scalar types (e.g. no arrays, no objects). The
Round()
expression falls into this definition and indeed is available to ACE/Jet with the same semantics as its VBA function equivalent. As anyone familiar with the ACE/Jet engine should know, though, the semantics can differ from the VBA equivalents e.g. ACE/Jet ANSI-92 Query Mode SQLreturns 'Long', whereas VBA
returns 'Integer'.
In other words,
Round()
wasn't going to be the problem here.