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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
UncleLewis
Responsive Resident
Responsive Resident

Pass Parameters To SQL Stored Procedure From Excel

Hi all,

 

Using Office M365 and SSMS 12.0.2269.0
I created and tested a Stored Procedure in AdventureWorksDW2017 - works great

Now I am trying to pass a parameter to the Stored Procedure in Excel through Power Query

 

I created a Table named "param" and entered the parameter

I then opened the Advanced Editor in Power Query and entered this code

 

let
DepartmentName=Excel.CurrentWorkbook(){[Name=”param”]}[Content]{0}[#”DepartmentName”],
Source = Sql.Database("PCName\SQL2017INSTANCE2", "AdventureWorksDW2017",
[Query="exec usp_SelectEmployees '"
& DepartmentName
&"'"])
in
Source

 

But I am receiving an Expression.SyntaxError:Invalid identifier

 

Do you see anything that looks incorrect?

I've been staring at it for an hour now.

 

Thanks

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi @UncleLewis , 

The & is used to connet the string, you could refer to @edhans 's suggestions to use ' ' ' in query. By the way, did you want to pass multiple parameters? If so, I think you could change your store prcedured like below(split_string is a split stored procedure)

 

 

create proc testp  @a varchar(20)  as
select *  from test1
where name in (select value from Split_String(@a, ','))

 

 

 Then change your M code like below(use " as Escape Characters )

 

 

let
    Source = Sql.Database("localhost", "newsql", [Query="exec testp '"&para&"'"])
in
    Source

 

783.PNG

Best Regards,
Zoe Zhi

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

3 REPLIES 3
edhans
Super User
Super User

I don't know how your stored procedure works, but the last thing you are passing is this:

"'"

 That single quote doesn't look right.

For a full overview of stored procedures and parameters from Power Query, see this article.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
UncleLewis
Responsive Resident
Responsive Resident

Thanks,

 

Doesn't the ampersand concatenate the different strings together?

So really everything between {} one continuous string broken over multiple lines?

 

Thanks

dax
Community Support
Community Support

Hi @UncleLewis , 

The & is used to connet the string, you could refer to @edhans 's suggestions to use ' ' ' in query. By the way, did you want to pass multiple parameters? If so, I think you could change your store prcedured like below(split_string is a split stored procedure)

 

 

create proc testp  @a varchar(20)  as
select *  from test1
where name in (select value from Split_String(@a, ','))

 

 

 Then change your M code like below(use " as Escape Characters )

 

 

let
    Source = Sql.Database("localhost", "newsql", [Query="exec testp '"&para&"'"])
in
    Source

 

783.PNG

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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 Kudoed Authors