Question

This select in EXCEL VBA results to numeric format in Excel:

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

But if I make some function on the column, it results as text format in Excel:

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')"

I've tried to_number(...), to_number(to_char(...)) but it didn't helped.

Why? How can I resolve this situation?

SOLUTION (convert column to numeric using SQL server cast function)

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

Solution

SOLUTION (convert column to numeric using SQL server cast function)

strSQL = "SELECT cast(col# as numeric(10, 2)) col# " _
         "FROM OPENQUERY(dtb, 'SELECT sum(col) col# from table')"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top