This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreLevel up your Power BI skills this month - build one visual each week and tell better stories with data! Get started
Hi there,
I have an Azure SQL Database that has a Stored Procedure that I need to call using Direct Query.
My Stored Procedure has no paramters.
I have scoured the forums and I have tried all 3 of the workarounds mentioned below using Advanced Options or Advanced Editor and I still get the following error:
Microsoft SQL: Incorrect syntax near the keyword 'DECLARE'. Incorrect syntax near ')'.
The workarounds I have tried are as follows:
Workaround # 1
DECLARE @SP VARCHAR(100) = 'SCHEMA.STOREDPROCEDURE'
EXEC (@SP)
Workaround # 2
let
Source = Sql.Database("SQL-AZURE-DATABASE", "SQL-AZURE-DATABASENAME", [Query="SELECT * FROM #(lf)OPENROWSET('SQLNCLI','trusted_connection=yes', 'exec SCHEMA.STOREDPROCEDURE')", CreateNavigationProperties=false])
in
Source
Workaround # 3
let
Source = Sql.Database("SQL-AZURE-DATABASE", "SQL-AZURE-DATABASENAME", [Query="DECLARE#(tab)@return_value int = 0; #(lf)#(lf)EXEC#(tab)@return_value = [SCHEMA].[STOREDPROCEDURE]; #(lf)#(lf)SELECT#(tab)'Return Value' = @return_value; "])
in
Source
Has anyone managed to do this in the above scenario?
Many thanks.
Solved! Go to Solution.
Try to specify database name inside OPENROWSET.
The problem is that behind the scenes Power BI executes
select * from ( --your query, e.g. EXEC spReport ) SourceQuery where 1 = 2
To test source validity. This is incorrect syntax when query is EXEC
Try to specify database name inside OPENROWSET.
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 34 | |
| 29 | |
| 29 | |
| 21 | |
| 18 |
| User | Count |
|---|---|
| 68 | |
| 45 | |
| 33 | |
| 24 | |
| 23 |