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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Leise
Regular Visitor

Direct Query using Stored Procedure from Azure SQL Database: Incorrect syntax near the keyword.

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.

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@Leise,

 

Try to specify database name inside OPENROWSET.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Burma
Helper I
Helper I

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

v-chuncz-msft
Community Support
Community Support

@Leise,

 

Try to specify database name inside OPENROWSET.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors