简体   繁体   English

Vba-在Ms Access上使用SQL时将数字转换为十进制

[英]Vba - Convert number to decimal when using SQL on Ms Access

Trying to convert a number value to decimal, with two decimals (,00), in vba when selecting value from MS Access table. 从MS Access表中选择值时,尝试在vba中将数字值转换为带有两位十进制(,00)的十进制。 The Quantity column is of type number and the code Im using to format it is 数量列是数字类型,用于格式化的代码是

Dim rstBody As DAO.Recordset
Dim orderBodyQuery As String
orderBodyQuery = "SELECT distinct CONVERT(Decimal(9,2), Quantity) FROM " + mainTable + " WHERE [" + uniqOrderColumn + "] = """ + order + """"
Set rstBody = CurrentDb.OpenRecordset(orderBodyQuery, dbOpenSnapshot)

This results in the error: 这导致错误:

Undefined function 'CONVERT' in expression 表达式中未定义的函数“ CONVERT”

As the error describes Im guessing Im using the wrong syntax here (SQL Server) but I can't find how to do this. 正如错误所描述的那样,我猜测我在这里使用了错误的语法(SQL Server),但我找不到如何执行此操作。 Please help 请帮忙

For display (text) it would be: 对于显示(文本),它将是:

Format([Quantity], "0.00")

To retrieve numeric values rounded by 4/5 to two decimals, it would be: 要检索将4/5舍入为两位小数的数值,它将为:

CCur(Format([Quantity], "0.00")) 

To set the Format property, use: 要设置Format属性,请使用:

"0.00", or just "Standard". 

Surprise! 惊喜! Access doesn't use T-SQL. Access不使用T-SQL。

I think you want the FORMAT() function. 我认为您需要FORMAT()函数。

What are differences between access sql 存取sql有什么区别

techonthenet.com/access/functions/ techonthenet.com/access/functions/

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

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