MySQL to Excel (Cell as reference)

Robert King

New Member
Joined
Mar 11, 2010
Messages
3
I'm using:
Windows 7 x64, MS Excel 07, MySQL 5.1 (localhost), ODBC Connector 5.16

Current status
I finally managed to use get data from MySQL into Excel Sheet. That works fine.

Question
Can I use a cell as reference in the MySQL query?

1 - SELECT * FROM users WHERE (id > 10) // works
1 - SELECT * FROM users WHERE (id > ?) // prompts Textinput, ends in error after input
2 - SELECT * FROM users WHERE (id > $d$1 ) // throws error, invalid

Is a VBA Script needed? If so please describe fool-proof :rolleyes:


*For me it looks like it's an easy and a common task.. I searched this forum and Google for a proper solution for hours now. I couldn't find a working solution :/
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi Robert,

In MSQuery the operation you want to perform is called a "Parameter Query". Maybe that is something you could Google.

It is rather simple in MSQuery. Basically, the record selection criteria in MSQuery is enclosed in square brackets
HTML:
[]
. This forces it to prompt the user for the record selection criteria.

In Excel there is a dialog box (Query properties I believe) that allows you to designate a cell from which the prompt should automatically accept its data.

HTH,

Gary
 
Upvote 0
Code:
SELECT * 
FROM users
WHERE (users_0.visits Between ? And ?)

For any reason this works!
Thank you guys very much!
 
Upvote 0
I'm using:
Windows 7 x64, MS Excel 07, MySQL 5.1 (localhost), ODBC Connector 5.16

Current status
I finally managed to use get data from MySQL into Excel Sheet. That works fine.

Question
Can I use a cell as reference in the MySQL query?

1 - SELECT * FROM users WHERE (id > 10) // works
1 - SELECT * FROM users WHERE (id > ?) // prompts Textinput, ends in error after input
2 - SELECT * FROM users WHERE (id > $d$1 ) // throws error, invalid

Is a VBA Script needed? If so please describe fool-proof :rolleyes:


*For me it looks like it's an easy and a common task.. I searched this forum and Google for a proper solution for hours now. I couldn't find a working solution :/

I would have thought it would be something like:

"SELECT * FROM users WHERE (id > " & Range("d1").Value & ")"
 
Upvote 0
Ha! even better...

Code:
SELECT * 
FROM users
WHERE (users_0.visits [$g$1])

=======

The params button was first disabled. I assumed it was not available for MySQL. After going through MSQuery it editable. I'll investigate the workflow tomorrow a bit closer. Maybe I'm just a bit too tired ;)
 
Upvote 0

Forum statistics

Threads
1,223,923
Messages
6,175,410
Members
452,640
Latest member
steveridge

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