excel - 在excel的odbc power query中使用sql字符串作为sql语句
问题描述
我希望使用一个字符串,该字符串从我的单元格中获取一些参数并将其用作我的 sql 语句,如下所示:
" select * from table where " & data_from_cells & " group by ...;"
将其存储为 sqlstring
let
mystring = sqlstring,
myQuery = Odbc.Query("driver={Oracle in etc etc etc", mystring)
我遇到了这个错误
Formula.Firewall: Query '...' (step 'myQuery') references other queries or steps, so it may not directly access a data source. Please rebuild this data combination.
现在显然我不能将外部查询和另一个查询结合起来——但我只使用 Excel 中的传递参数作为我的 sql 字符串?我也希望使用WITH
关键字来使用参数进行嵌套查询,但它甚至不允许我将 excel 中的值与 sql 语句结合起来。
需要明确的是,data_from_cells
被转换并格式化为字符串。
解决方案
当执行其他操作的其他查询调用执行其他操作的查询时,有时您会遇到防火墙问题。
解决这个问题的方法是在一个查询中完成所有事情。
解决这个问题而不会产生可怕的代码的方法是将调用的查询从返回结果更改为返回结果的 函数。
对于 sqlstring:
() => " select * from table where " & data_from_cells & " group by ...;" // returns a function that gets the query string when called
那么你的“myQuery”查询可以是
let
mystring = sqlstring(), //note the parentheses!
myQuery = Odbc.Query("driver={Oracle in etc etc etc", mystring)
推荐阅读
- python - Python ggplot 和 ggplotly
- vue.js - 在 vue.js 应用程序中将静态内容(例如国家代码)存储在哪里?
- r - 从一组数字中提取一个数字
- angularjs - angularJS:嵌套的 ng-repeat,orderBy 不起作用
- reactjs - 在 Electron 中调用 setZoomFactor 后,来自 getBoundingClientRect 的数据不正确
- scala - Scala、Cats、Intellij IDEA:修复语法和编译错误?
- google-apps-script - 谷歌表格脚本的相对参考
- c# - 如何在 webapi 中上传 blob 并转换为图像
- javascript - 在jQuery中检查未定义的变量,其名称的一部分是变量
- javascript - 显示来自给定 url 的图像