SQL 通过经典 ADO - 未定义函数“Round”?

发布于 2024-07-19 03:58:09 字数 469 浏览 6 评论 0原文

我正在开发一个遗留产品,并且我有一些通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

踏月而来 2024-07-26 03:58:09

EDIT2:评论中的正确解决方案:

shahkalpesh:如果它通过 Access 执行良好,则可能是 Access 具有可用的 DLL,该 DLL 具有 Round 函数。 您使用的连接字符串是什么?

Stimul8d:我不知道它怎么能是这样,所以用连接字符串来做。 此代码适用于所有其他机器,无需任何更改; 只是不在我的身上。

安多玛:嗯,这就是你的问题,你的机器坏了。 您仍然可以安装 vb6 sp6也许吧。

Stimul8d:嗯,SP6 修复了它。 干杯 Anndomar,不知道为什么 SP6 修复了它,但它确实修复了!

编辑:根据您的评论

不幸的是,当你跑步时
来自 Access 外部的查询(当您
来自VB),你唯一的联系
数据库是通过Jet
引擎,它什么都不知道
关于大多数 VBA 函数。 没有
解决这个问题,除了返回
将数据传输到您的 VB 应用程序并
使用那里的数据的函数。

后来又发了两篇文章:

我解决了这个问题。 更新了我的VB
使用 Service Pack 6...花了
关心问题。

旧答案在这里:

尝试 FLOOR() 而不是 ROUND()。

要将某些内容四舍五入到最接近的整数,您可以:

declare @floatmyboat float
set @floatmyboat = 1.51
select floor(@floatmyboat+0.5)

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:

Unfortunately, when you are running
queries from outside of Access (as you
are from VB), your only connection to
the database is through the Jet
engine, which doesn't know anything
about most VBA functions. There's no
way around this, other than to return
the data to your VB application and
use the functions on the data there.

And two posts later:

I solved the problem. Updated my VB
with the Service Pack 6... it took
care of the problems.

Old answer here:

Try FLOOR() instead of ROUND().

To round something to the nearest integer, you could:

declare @floatmyboat float
set @floatmyboat = 1.51
select floor(@floatmyboat+0.5)

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().

不喜欢何必死缠烂打 2024-07-26 03:58:09

SQL Server 中也存在 round() 函数。
唯一的区别是:在 Access 中,精度是一个可选参数,但在 SQL Server 中,您必须指定它。

因此,这仅适用于 Access,但不适用于 SQL Server:

select round(Column) from Table

这适用于 Access SQL Server:

select round(Column,1) from Table

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:

select round(Column) from Table

This will work in Access and SQL Server:

select round(Column,1) from Table
断桥再见 2024-07-26 03:58:09

可能是 Access 具有 DLL
可用它,其中有回合
功能

ACE/Jet 通过 VBA 使用共享表达式服务。 概括地说,ACE/Jet 支持所有其参数和返回值是标量类型(例如,没有数组、没有对象)的 VBA5 函数(与方法不同)作为表达式。 Round() 表达式属于此定义,并且确实可用于 ACE/Jet,其语义与其等效的 VBA 函数相同。 不过,熟悉 ACE/Jet 引擎的人都应该知道,语义可能与 VBA 等效项不同,例如 ACE/Jet ANSI-92 查询模式 SQL

SELECT TYPENAME(ROUND(5, 1))

返回“Long”,而 VBA

?Typename(Round(5, 1))

返回“Integer”。

换句话说,Round() 不会成为这里的问题。

it could be that Access has the DLL
available to it, which has the Round
function

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 SQL

SELECT TYPENAME(ROUND(5, 1))

returns 'Long', whereas VBA

?Typename(Round(5, 1))

returns 'Integer'.

In other words, Round() wasn't going to be the problem here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文