Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel: Use a cell value as a parameter for a SQL query

Tags:

excel

odbc

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.

like image 656
GetFree Avatar asked Aug 16 '09 23:08

GetFree


People also ask

How can I reference a cell's value in power query?

So to get the value of cell we can simply write this code into first step of query: = Excel. CurrentWorkbook(){[Name="nice_table"]}[Content][nice_column]{0}


1 Answers

I had the same problem as you, Noboby can understand me, But I solved it in this way.

SELECT NAME, TELEFONE, DATA FROM   [sheet1$a1:q633] WHERE  NAME IN (SELECT * FROM  [sheet2$a1:a2]) 

you need insert a parameter in other sheet, the SQL will consider that information like as database, then you can select the information and compare them into parameter you like.

like image 101
Joaquim Avatar answered Oct 02 '22 22:10

Joaquim