Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
skrishna
Regular Visitor

Stored Procedure usage in Azure SQL Database with Direct Query Mode

 

 

We created stored procedures in Azure SQL Database and trying to use them power BI report with Direct Query mode. But getting the error like "Microsoft SQL: Incorrect syntax near the keyword 'EXEC'. Incorrect syntax near ')'.

 

Another question is how to set the connection string as global so that I can use the same connection string in every report?

 

Please help me with the solution

3 REPLIES 3
r_medina
New Member

I found a way to make it work with an On-Prem SQL Server 2016 database and Power BI Gateway: you need to copy the syntax that SQL Server generates when running a Stored Procedure.

 

In Power BI use the Advanced Editor to change your query to look something like this:

 

let

    Source = Sql.Database("MySqlServerName", "MyDbName", [Query="DECLARE#(tab)@return_value int = 0; #(lf)#(lf)EXEC#(tab)@return_value = [MySchema].[MySP]; #(lf)#(lf)SELECT#(tab)'Return Value' = @return_value; "])

in

    Source

 

Hope this helps in your Azure SQL DB,

v-haibl-msft
Microsoft Employee
Microsoft Employee

@skrishna

 

For your first requirement, it is not supported now. Please vote on this idea.

For the second one, could you please explain more about the connection string? How do you want to use it in the report?

 

Best Regards,
Herbert

I found a way to make it work with an On-Prem SQL Server 2016 database and Power BI Gateway: you need to copy the syntax that SQL Server generates when running a Stored Procedure.

 

In Power BI use the Advanced Editor to change your query to look something like this:

 

let

    Source = Sql.Database("MyServerName", "MyDbName", [Query="DECLARE#(tab)@return_value int = 0; #(lf)#(lf)EXEC#(tab)@return_value = [MySchema].[MyStoredProcedure]; #(lf)#(lf)SELECT#(tab)'Return Value' = @return_value; "])

in

    Source

 

Hope this helps in your Azure SQL DB.......................... -RM

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors