vba 投射和求和函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19206080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 23:41:22  来源:igfitidea点击:

Cast and Sum functions

sqlexceloraclevba

提问by user2851053

I am writing a macro which pulls data from Oracle and displays in Excel. In Oracle DB we have a custom table with a column Named "Calculated_Quantity". The datatype of this column is BINARY_DOUBLE. However when I write a query in Excel macro to retreive this column, I get the error as "Data Type is not Supported". So I had to use "Cast" function to bypass this error.

我正在编写一个宏,它从 Oracle 中提取数据并在 Excel 中显示。在 Oracle DB 中,我们有一个带有名为“Calculated_Quantity”的列的自定义表。此列的数据类型为 BINARY_DOUBLE。但是,当我在 Excel 宏中编写查询以检索此列时,出现“不支持数据类型”的错误。所以我不得不使用“Cast”功能来绕过这个错误。

Now I need to sum this column. If I write the statement as

现在我需要总结这一列。如果我将语句写为

Select Id, SUM(CAST(CALCULATED_QUANTITY AS NUMBER(10))) Qty 
from DW.SAMPLE

it works fine, but the calculation is wrong.

它工作正常,但计算错误。

If I write

如果我写

Select Id, CAST(SUM(CALCULATED_QUANTITY AS NUMBER(10))) Qty 
from DW.SAMPLE

I get an error as missing right parenthesis. The parenthesis seem to be correct. Help please! –

我得到一个错误,因为缺少右括号。括号似乎是正确的。请帮忙!——

回答by juergen d

Select Id, CAST(SUM(CALCULATED_QUANTITY) AS NUMBER(10)) Qty 
from DW.SAMPLE