我正在通过Excel使用power查询外部数据库。我想要做的是基于单元格值填充where子句,例如,我的sql语句会读到以下内容
Select *
From employees
where hiredate between Sheet1!A1 and Sheet2!A2
我尝试了上面的语法,但它不起作用,但我认为它说明了我想要实现的目标。
如何将参数从Excel表传递到power查询语法?
编辑
我尝试跟随blog.oraylis.de (不是实际的链接,链接在注释中),但是当我试图执行我的语句时,我得到了下面的错误
DataSource.Error ODBC:错误4203错误:列"start_p“不存在;
我创建了一个名为it参数的表,添加了头和值,我尝试运行的完整SQL如下:
let
startp_Param = Excel.CurrentWorkbook(){[Name="Parameter"]}[Content],
startp_Value = startp_Param {0}[Value],
endp_Param = Excel.CurrentWorkbook(){[Name="Parameter"]}[Content],
endp_Value = endp_Param {1}[Value],
Source = Odbc.Query("dsn=postgresql", "Select * FROM employees where hiredate BETWEEN startp_Value AND endp_Value")
in
Source
编辑# 2
我修改了查询,如下所示
"Select *
FROM employees
where hiredate BETWEEN " & startp_Value & " AND " & endp_Value
但是,现在出现的错误是:
"We cannot apply operator & to types Text and Number"
发布于 2016-04-25 17:52:35
startp_Value和endp_Value是Power查询中的步骤,因此您必须使用&将其添加到字符串中,如下所示:
Source = Odbc.Query("dsn=postgresql", "Select * FROM employees where hiredate BETWEEN " & startp_Value & " AND " & endp_Value
这并不能处理清除SQL查询的问题,因此您可能希望对startp_Value和endp_Value (例如,转换为日期,然后返回到文本)进行消毒处理。
https://stackoverflow.com/questions/36845106
复制相似问题