参数
TestID
已定义,并且严格来说是一个数值。
但是无论我嵌入它,Power Query 都会抛出错误:
我们无法将运算符
应用于文本和数字类型。&
详情:
运算符=&
TestID = Excel.CurrentWorkbook() {[Name="TestID"]}[Content]{0}[Column1]
select ... where time@timestamp between (select distinct max([time@timestamp]) from [POD01EVENTLOG] where [data_format_4] = 1 and [data_format_0] = "&TestID&") and (select distinct max([time@timestamp]) + 60 from [POD01EVENTLOG] where [data_format_4] = 1 and [data_format_0] = "&TestID&")
我的 Power Query M 代码是:
let
TestID = Excel.CurrentWorkbook() {[Name="TestID"]}[Content]{0}[Column1],
Source = Sql.Database("SERVERNAME", "DBNAME",
[Query="
SELECT *
from [POD01RAWDATA]
where
time@timestamp
between
(select distinct max([time@timestamp]) from [POD01EVENTLOG] where [data_format_4] = 1 and [data_format_0] = "&TestID&")
and
(select distinct max([time@timestamp]) + 60 from [POD01EVENTLOG] where [data_format_4] = 1 and [data_format_0] = "&TestID&")
"])
in
Source
您无法连接数字和文本,因此在连接之前将 testid 转换为 TEXT
" & Number.ToText(TestID,"D") & "
或者做
&Text.From(TestID)&