原始列的更改将导致Excel工作表中的TEXT格式

时间:2012-10-12 11:22:39

标签: oracle excel-vba openquery vba excel

EXCEL VBA中的此选择会在Excel中生成数字格式:

strSQL = "SELECT * FROM OPENQUERY(dtb, 'SELECT col from table')"

但是如果我在列上创建了一些函数,它会在Excel中以 text 格式生成:

strSQL = "SELECT * FROM OPENQUERY(dtb, 'SELECT sum(col) from table')"
strSQL = "SELECT * FROM OPENQUERY(dtb, 'SELECT col*1.0  from table')"
strSQL = "SELECT * FROM OPENQUERY(dtb, 'SELECT col-1    from table')"

我已尝试to_number(...)to_number(to_char(...))但它没有帮助。

为什么呢?我该如何解决这种情况?

解决方案(使用SQL Server强制转换函数将列转换为数字)

strSQL = "SELECT cast(col# as numeric(10, 2)) col# " _
         "FROM OPENQUERY(dtb, 'SELECT sum(col) col# from table')"

1 个答案:

答案 0 :(得分:0)

解决方案(使用SQL Server强制转换函数将列转换为数字)

strSQL = "SELECT cast(col# as numeric(10, 2)) col# " _
         "FROM OPENQUERY(dtb, 'SELECT sum(col) col# from table')"