我的数据有2个小数位(见图)并使用该函数减去这两个值但我得到一个舍入数字作为我的输出。我试图将浮点数添加到下面的表达式"(L.M123_Corr_Integrator-R.M123_Corr_Integrator)"但是它抛出了一个错误。我不熟悉sql / vba代码,所以任何有用的信息都会有所帮助。
sql = "UPDATE (SELECT R.DateLog , ( L.M123_Corr_Integrator - R.M123_Corr_Integrator) AS Gross " & _
"FROM tbl_M123_DataSet AS L INNER JOIN tbl_M123_DataSet AS R " & _
"ON L.DateLog = DATEADD('d', 1, R.DateLog)) as T " & _
"INNER JOIN tbl_M123_DataSet ON tbl_M123_DataSet.DateLog = T.DateLog " & _
"Set Gross_kWh = Gross"
dbs.Execute sql, dbFailOnError
MsgBox dbs.RecordsAffected & " rows affected on column GrossKW"
未经过混淆的查询看起来像这样:
UPDATE
(
SELECT
R.DateLog,
L.M123_Corr_Integrator - R.M123_Corr_Integrator AS Gross
FROM
tbl_M123_DataSet AS L
INNER JOIN tbl_M123_DataSet AS R
ON L.DateLog = DATEADD('d', 1, R.DateLog)
) AS T
INNER JOIN tbl_M123_DataSet
ON tbl_M123_DataSet.DateLog = T.DateLog
SET Gross_kWh = Gross
答案 0 :(得分:1)
在我看来,您将表字段Gross_kWh
设置为整数。在表格设计视图中,突出显示行Gross_kWh
并将其数字类型设置为' Double'。
另请注意,Access有时会将数字用于显示,但小数准确数字会正确存储在表格中。