Skip to content
Advertisement

Passing date variable in Power Query to ODBC source

I have managed to extract a date from Excel (that the user can amend).[A named range called DateB]. I want to be able to pass that to a variable in the sql part of Power Query so that various checks can be made before passing the data back. However, I cannot get the variable @man_Date to accept the date that I have extracted.

RDP3 returns 30/06/2020 correctly at that stage.

However, in the source part, if I have ” & RDP3 & ” I am told it won’t work with the &s If I remove them I am then left with the error message “Token comma expected”.

This is the code I have at the start of the query. I also use the @Man_Date in a subquery as well.

What would be the correct syntax to use for RDP3? @Man_Date works with a manual entry (@Man-Date = ‘2020-06-30’) I have tried various date formats, but cannot seem to get this to work. It seems both parts work independently. It’s just tying them together that seems to be the sticking point.

Advertisement

Answer

I have now learnt that I can only pass text to the sql. So I have used the below breakdown to get the date into a text form for SQL.

It is the RDC4 part that converts it to a useable text date and is used throughout the query.

Hope that helps someone else.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement