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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.