Forum Discussion
Syndicate_Admin
3 years agoAdministrator
Issue passing variable to SQL Query
Hello I am writing a Power Query to extract data from a SQL Database. I wish to filter the data extracted. I have tried one step being the SQL query, and then the second step the filter, but th...
Anonymous
3 years agoNot applicable
This will work a thousand times faster if you fix the real problem, which is that your parameter isn't a value, it's a table. You should right click then drill down on the value to make it just an integer value by itself. Then the name of this query is the variable name containing your value. Do that with your APStart and APEnd Queries. So if you are in the advanced editor, you would amend the SQL add this before your final quotation mark ("), AKA the end of your WHERE statement:
AND AccountingPeriod >= "&ApStart&" AND AccountingPeriod <= "&APEnd&
Play around with that. My point is that if your variable is an actual value, you can refer to it in the SQL using the "&QueryName&" syntax. Folds right into the SQL.
--Nate