将参数从excel工作簿中的单元格传递到SQL查询

时间:2021-01-15 01:01:51

Please note I have found solutions to this in Excel 2007, 2010, 2013 etc but nothing that relates directly to 2016.

请注意我在Excel 2007,2010,2013等中找到了解决方案,但没有任何与2016年直接相关的内容。

I bring in a query to Excel by using Data / Get Data / From Database / From SQL Server Database.

我通过使用数据/获取数据/从数据库/从SQL Server数据库引入Excel查询。

What I want to do is restrict 1 column in the data it retrieves to a specific value.

我想要做的是将它检索的数据中的1列限制为特定值。

In my exact example there is a date column and I want a cell in the spreadsheet to pass the date value to filter the returned query data.

在我的确切示例中,有一个日期列,我希望电子表格中的单元格传递日期值以过滤返回的查询数据。

1 个解决方案

#1


0  

For this application, I don't think you need to actually pass the date as a parameter to your query. You can just use the date from the cell as a filter after you've loaded your query into the Query Editor. As a result of query folding, Excel should automatically pass it into the WHERE clause of the native query it sends to the SQL Server Database.

对于此应用程序,我认为您不需要将日期作为参数传递给查询。将查询加载到查询编辑器后,您可以使用单元格中的日期作为过滤器。作为查询折叠的结果,Excel应自动将其传递到它发送到SQL Server数据库的本机查询的WHERE子句中。

If you don't know how to reference a cell value in the Query Editor, please see this question:

如果您不知道如何在查询编辑器中引用单元格值,请查看以下问题:

How can I reference a cell's value in a Power Query

如何在Power Query中引用单元格的值

#1


0  

For this application, I don't think you need to actually pass the date as a parameter to your query. You can just use the date from the cell as a filter after you've loaded your query into the Query Editor. As a result of query folding, Excel should automatically pass it into the WHERE clause of the native query it sends to the SQL Server Database.

对于此应用程序,我认为您不需要将日期作为参数传递给查询。将查询加载到查询编辑器后,您可以使用单元格中的日期作为过滤器。作为查询折叠的结果,Excel应自动将其传递到它发送到SQL Server数据库的本机查询的WHERE子句中。

If you don't know how to reference a cell value in the Query Editor, please see this question:

如果您不知道如何在查询编辑器中引用单元格值,请查看以下问题:

How can I reference a cell's value in a Power Query

如何在Power Query中引用单元格的值