简体   繁体   中英

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

I have seen the reference posts on SO here and here . I have tried the responses from the forums but can not successfully run my PowerQuery.

So far I have named both my Start and End date cells as "StartDate" and "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]

Now, Looping back to my original PowerQuery, the where clause to set these date parameters looks as such:

 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. Maybe I am missing a step or not calling the values properly in my SQL...not too sure. 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

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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