|
本帖最后由 wang93915066 于 2024-7-5 16:25 编辑
求助高人,Powerquery -在SQL查询中引用Excel单元格值
目的:根据Sheet1中A1和A2单元格的值 (例如:20240601 和20240630),进行PQ查询SQL数据库并反馈相应的内容
网上看来的资料如下,
https://stackoverflow.com/questi ... ery-where-statement
示例代码:
let Source = Sql.Database("localhost", "StackOverflowTest", [Query="SELECT #(lf) Model, Factory, TargetTime, TotalEvalMins #(lf)FROM #(lf) AMSView #(lf)WHERE #(lf) WeekNumber = " & Number.ToText(week_number)])in Source
实际应用的需求如下:
将excel文件中sheet1的A1单元格的值传到 ValueFromA1 , A2单元格的值传到 ValueFromA2 , 但是自己在使用过程中不知道如何修改
let
Source = Sql.Database(
{"192.168.0.254", "TESTDB"},
let
query = "select COPTG.TG004,COPTG.TG006,TG045+TG046 FROM COPTH LEFT JOIN COPTG ON TG001 = COPTH.TH001 AND TG002 = COPTH.TH002 WHERE COPTG.TG023 = 'Y' AND TG003 BETWEEN '" & ValueFromA1 & "' AND '" & ValueFromA2 & "' GROUP BY COPTG.TG006,COPTG.TG004,TG045+TG046 ORDER BY TG006"
in
query
)
in
Source
|
|