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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
Employee
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 AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.