views:

1356

answers:

2

I'm using MS Excel to get data from a MySQL database through ODBC.
I successfully get data using an SQL query. But now I want that query to be parameterized.
So I wonder If it is possible to use a cell value (a spreadsheet cell) as a parameter for such a query.
For example, for this query:

select name from user where id=1

I'd like to get the id value from, say, cell D4 in the spreadsheet.

Is that the proper approach to parameterize a query? and how can I do it?

Thanks.

+1  A: 
queryString = "SELECT name FROM user WHERE id=" & Worksheets("Sheet1").Range("D4").Value
barrowc
I guess I have to do that in a VBA script, right? I dont think I could type that expression inside the SQL window.
GetFree
That's VBA, yes
barrowc
A: 

If you are using microsoft query, you can add "?" to your query...

select name from user where id= ?

that will popup a small window asking for the cell/data/etc when you go back to excel.

pojomx