Number as string as column name?

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
871
I'm having a problem running an SQL query from Excel VBA code and my query is:

SELECT SUM (10) FROM [Ostoaineisto$]

Which gives me some weird number, 1000, as the answer

As soon as I rename the column as, say, "Mike", the result with query

SELECT SUM (Mike) FROM [Ostoaineisto$]

gives the correct number, 80, as the answer.

Any easy trick to tell to Excel/VBA/SQL/AdoDB that this "10" is not a number, it's a column name? I actually need to run the query against every single column there, so some simple "for each, return sum"-function would solve this too.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
871
I worked around this by just opening the DB first, renaming the fields like "10"->"a10a" ran queries and the named them back again. Doesn't necessarily follow all rules of art, but it works.
 

Forum statistics

Threads
1,141,289
Messages
5,705,524
Members
421,399
Latest member
hjweiss00

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top