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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
amaaiia
Super User
Super User

Parameters for table name in stored procedure

I want to have a stored procedure to call it from Lookup activity in several Data Pipelines. I want the procedure to be as follows:

amaaiia_0-1710340021193.png

I want the "from" table to be ingested with parameters. I've tried with @lakehouse_name.@schema_name.@table_name but it's not working. I've seen I have QUOTENAME option but I don't know how to perform the query.

1 ACCEPTED SOLUTION
govindarajan_d
Super User
Super User

Hi @amaaiia ,

 

Declare the parameters as NVARCHAR. It will show an error but still it will work. After that use SET to form the string you want to execute and then use 'sp_executesql' with the string you formed. Make sure you use N in front of the strings.

 

In the below example, I have formed two strings one with Table name and the other with select query using the table name. 

DECLARE @MergeQuery NVARCHAR(MAX), @TableName NVARCHAR(MAX);
SET @TableName = N'dbo.Product_Info';
SET @MergeQuery = N'SELECT * FROM ' + @TableName;

EXEC sp_executesql @MergeQuery;

View solution in original post

3 REPLIES 3
govindarajan_d
Super User
Super User

Hi @amaaiia ,

 

Declare the parameters as NVARCHAR. It will show an error but still it will work. After that use SET to form the string you want to execute and then use 'sp_executesql' with the string you formed. Make sure you use N in front of the strings.

 

In the below example, I have formed two strings one with Table name and the other with select query using the table name. 

DECLARE @MergeQuery NVARCHAR(MAX), @TableName NVARCHAR(MAX);
SET @TableName = N'dbo.Product_Info';
SET @MergeQuery = N'SELECT * FROM ' + @TableName;

EXEC sp_executesql @MergeQuery;

Hi @amaaiia 


We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet.
In case if you have any resolution please do share that same with the community as it can be helpful to others.
Otherwise, will respond back with the more details and we will try to help.


Thanks.

Hi @amaaiia 

 

We haven’t heard from you on the last response and was just checking back to see if you have a resolution yet. In case if you have any resolution please do share that same with the community as it can be helpful to others.
If you have any question relating to the current thread, please do let us know and we will try out best to help you.
In case if you have any other question on a different issue, we request you to open a new thread.


Thanks.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June FBC25 Carousel

Fabric Monthly Update - June 2025

Check out the June 2025 Fabric update to learn about new features.