简体   繁体   English

Excel - 使用单元格值作为传递日期 ODBC SQL PowerQuery

[英]Excel - Using cell value as pass-through date ODBC SQL PowerQuery

I have seen the reference posts on SO here and here .我在这里这里看到了关于 SO 的参考帖子。 I have tried the responses from the forums but can not successfully run my PowerQuery.我已经尝试了论坛的回复,但无法成功运行我的 PowerQuery。

So far I have named both my Start and End date cells as "StartDate" and "EndDate".到目前为止,我已将开始和结束日期单元格命名为“StartDate”和“EndDate”。 From there I have created two blank queries, both renamed to StartDateValue and EndDateValue and look like this: (StartDate) => Excel.CurrentWorkbook(){[Name=StartDate]}[Content]{0}[Column1] and (EndDate) => Excel.CurrentWorkbook(){[Name=EndDate]}[Content]{0}[Column1]从那里我创建了两个空白查询,都重命名为 StartDateValue 和 EndDateValue,如下所示: (StartDate) => Excel.CurrentWorkbook(){[Name=StartDate]}[Content]{0}[Column1](EndDate) => Excel.CurrentWorkbook(){[Name=EndDate]}[Content]{0}[Column1]

Now, Looping back to my original PowerQuery, the where clause to set these date parameters looks as such:现在,循环回到我原来的 PowerQuery,设置这些日期参数的 where 子句如下所示:

 AND A."CREATED_DTM" BETWEEN Excel.Workbook(File.Contents(StartDateValue("StartDate"))) and Excel.Workbook(File.Contents(EndDateValue("EndDate")))
          

Doing so doesnt seem to work.这样做似乎不起作用。 Though if I replace my "failed" call and simply input date values like '5/1/2022' my script executes normally.虽然如果我替换我的“失败”调用并简单地输入日期值,如'5/1/2022'我的脚本将正常执行。 Maybe I am missing a step or not calling the values properly in my SQL...not too sure.也许我错过了一个步骤或者没有在我的 SQL 中正确调用这些值......不太确定。 Any information on this helps, thanks.任何有关这方面的信息都有帮助,谢谢。

I'm not sure how you plan to use it in powerquery, but you likely want the contents of the StartDate and EndDate cell in text format within the query, so ditch your two functions and just include these rows in your code我不确定您打算如何在 powerquery 中使用它,但您可能希望在查询中以文本格式显示 StartDate 和 EndDate 单元格的内容,因此放弃您的两个函数,只需将这些行包含在您的代码中

SD = Text.From(Date.From(Excel.CurrentWorkbook(){[Name="StartDate"]}[Content]{0}[Column1])),
ED = Text.From(Date.From(Excel.CurrentWorkbook(){[Name="EndDate"]}[Content]{0}[Column1])),

then you can use SD and ED as necessary那么您可以根据需要使用 SD 和 ED

text = "this is some text with " & SD & " and " & ED & " in them"

= Sql.Database("SERVER", "DATABASE", [Query="SELECT * FROM [TABLE] WHERE weekStartDate>='"&SD&"'"])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM