Excel:使用单元格值作为SQL查询的参数 [英] Excel: Use a cell value as a parameter for a SQL query
问题描述
我使用MS Excel从MySQL数据库通过ODBC获取数据。
我使用SQL查询成功获取数据。但现在我希望该查询被参数化。
所以我想知道如果可以使用单元格值(电子表格单元格)作为这样的查询的参数。
对于例如,对于此查询:
从用户选择名称,其中id = 1
/ pre>
我想从电子表格中的单元格D4中获取id值。
这是参数化查询的正确方法吗?我该怎么做?
谢谢。
解决方案有与你相同的问题,Noboby可以理解我,但我以这种方式解决了。
选择名称,电话,数据
FROM [sheet1 $ a1:q633]
WHERE NAME IN(SELECT * FROM [sheet2 $ a1:a2])
您需要在其他工作表中插入一个参数,SQL会将这些信息视为
数据库,然后您可以选择信息并将其与您喜欢的参数进行比较。 >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.
解决方案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.
这篇关于Excel:使用单元格值作为SQL查询的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!