Forum Discussion
Using an Excel named range as the SQL for a power query
- 1 year ago
either that, or source your SQL query text from elsewhere (like a parameter, or text file on a sharepoint)
Hi Ibendlin,
Thank you for your reply but I don't quite follow what's in that link, I'm assuming it's the answer by TheRizza you were pointing me to.
Apologies if I've not been clear but the question in that link was "How to run a SQL query on an Excel table?" where as I'm trying to run a query (that's in a named range in Excel) on a SQL database and return the results to Excel.
I've amended what's in Advanced Editor to:
let
Source = Sql.Databases("MyServer"),
MyData1 = Source{[Name="MyDatabase"]}[Data],
Query = [sql_query]
in
MyData1
But this still doesn't work, all I get is a list of all tables in the SQL database.
Thanks
Ah, that makes more sense. You need to specify the entire actual SQL query. The query alias is not usable.
- HumphreyDog1 year agoNew Member
So to confirm that I understand you, it's not possible to use the SQL script that's in the named range, rather I'd have to actually specify the script. So when the ZZZ needs changing I'd have to do that manually, update the Power Query and re-run each time?
- lbendlin1 year agoSuper User
either that, or source your SQL query text from elsewhere (like a parameter, or text file on a sharepoint)
- HumphreyDog1 year agoNew Member
OK, thanks for you advice Ibendlin