Number as string as column name?

Jaymond Flurrie

Well-known Member
Joined
Sep 22, 2008
Messages
919
Office Version
  1. 365
Platform
  1. Windows
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

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
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.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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
Back
Top