在 MS Access 中使用 Sql 中的数学函数

发布于 2024-07-30 00:32:38 字数 308 浏览 2 评论 0原文

我使用 MS Access 在 SQL 视图中设计了一个查询:

select floor(num1) from t1;

当我运行它时,我得到“未定义的函数层”。

对于 CeilModPowerSignSqrtTruncinitcap 函数。

Access数据库引擎的SQL语法是否有等效的功能?

I designed a query in SQL View using MS Access:

select floor(num1) from t1;

When I run it, I get "undefined function floor".

I get similar errors for Ceil, Mod,Power, Sign, Sqrt, Trunc, and initcap functions.

Does the Access database engine's SQL syntax have equivalent functions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

剑心龙吟 2024-08-06 00:32:40

如前所述,Floor 在 access 中不可用,您应该使用 int() 作为替代。 如果您坚持使用 Floor,您始终可以在 mdb 文件中创建一个类似于下面的 vba 模块函数,但这可能有点过头了。

Public Function floor(dblIn As Double, dec As Integer) As Double
  decPosition = InStr(Str(dblIn), ".")
  x = Left(dblIn, decPosition + dec - 1)
  floor = x
End Function

与上面描述的其他数学运算类似,您可以创建其他函数来创建这组功能。

As mentioned, Floor isn't available in access, you should use int() as an alternative. If you insist on using Floor, you could always create a vba module function in your mdb file similar to below but that is probably overkill.

Public Function floor(dblIn As Double, dec As Integer) As Double
  decPosition = InStr(Str(dblIn), ".")
  x = Left(dblIn, decPosition + dec - 1)
  floor = x
End Function

Similar to the other math operations you described above you may create additional functions to create this set of functionality.

她说她爱他 2024-08-06 00:32:39
Public Function Floor(ByVal x As Double) As Double
'Be Because VBA does not have a Floor function.
'Works for positive numbers
'Turns 3.9 -> 3
'Note: Round(3.9) = 4

    Dim s As String, dPos As Integer
    s = CStr(x)
    dPos = InStr(s, ".")
    Floor = CLng(Left(s, dPos - 1))
End Function
Public Function Floor(ByVal x As Double) As Double
'Be Because VBA does not have a Floor function.
'Works for positive numbers
'Turns 3.9 -> 3
'Note: Round(3.9) = 4

    Dim s As String, dPos As Integer
    s = CStr(x)
    dPos = InStr(s, ".")
    Floor = CLng(Left(s, dPos - 1))
End Function
情泪▽动烟 2024-08-06 00:32:39

将 Floor() 替换为 Int()。 我通过在 Access 帮助文件中搜索来了解这一点,在本例中,在查询设计器中按 F1,然后搜索“函数”。 这让我看到了一个比较 VBA 和 T-SQL 函数的帮助主题。

您可能应该查看Access 数据库引擎 SQL 参考。 我找不到关于 Jet/ACE 和 Access 表达式服务支持的函数的良好在线参考。 由于某种未知的原因,自 Jet 3.0 起,Access 帮助就不再包含 Jet/ACE 表达式,并且这一过时的资源最终在一两年前从 MSDN 中删除了:(

请记住,在 Access 外部使用的 Jet/ACE 表达式服务支持在 Access 2007 中运行 SQL 时,可以使用 Access 表达式服务实现更小的函数子集。一般来说,涉及简单数据类型(不同于数组或对象)的 VBA5 函数(不同于方法)是在 Access 用户界面之外受支持;有关函数名称的大致列表,请参阅 这篇 MSDN 文章

此外,VBE 帮助中的函数参考应该是一个起点。

帮助文件并不完美,但稍微搜索一下应该可以找到您需要的内容。

Replace Floor() with Int(). I learned this by searching in the Access help files, in this case, hitting F1 while in the query designer, and searching for "functions." That took me to a help topic comparing VBA and T-SQL functions.

You should probably have a look at the Access database engine SQL Reference. I can't find a good online reference for functions that are supported through the Jet/ACE and Access expression services. For some unknown reason, the Access Help has not included Jet/ACE expressions since Jet 3.0 and this aged resource was finally removed from MSDN a year or two ago :(

Keep in mind that the Jet/ACE expression service for use outside Access supports a much smaller subset of functions that is possible using the Access Expression Service when running your SQL inside Access 2007. Broadly speaking, the VBA5 functions (as distinct from methods) that involve simple data types (as distinct from, say, arrays or objects) are supported outside of the Access user interface; for an approximate list of function names see the 'Use Sandbox mode operations with Jet 4.0 Service Pack 3 and later' section of this MSDN article.

Also, the functions reference in the VBE help should be a starting place.

The help files are not perfect, but a little searching ought to get you what you need.

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