Adam
Adam

Reputation: 37

Concat Azure Data Factory Pipeline parameters in SQL Query

Azure Data Factory Pipeline is getting the SQL query stored in a database table. Eg. Query:

Select * from employees where first_name = 'Sam' and last_name = 'mathew'

I need to update the query in such a way that fname and lname will be a parameter in the azure data factory pipeline say pipeline().parameters.fname and pipeline().parameters.lname

How will the query be modified to use these pipeline parameters in SQL query?

Note: SQL Query is stored in database table. The pipeline will fetch the SQL Query in Copy Data Pipeline Step

Upvotes: 1

Views: 920

Answers (1)

Rakesh Govindula
Rakesh Govindula

Reputation: 11284

As suggested by @Nandan, you have to do this by creating a stored procedure in the database and pass the pipeline parameters in copy activity.

Please follow the demonstration below for that:

  • Here I am copying the selected data from query to a csv file in blob. You can copy wherever you want.

  • This is my sample SQL table. enter image description here

  • I am creating stored procedure in the database like below with fname and lname as parameters and use concat() in sql.

create or alter procedure dbo.proc1 @fname nvarchar(32),@lname nvarchar(32)
as
begin
    select concat(firstname,' ',lastname) as employee_name from [dbo].[employees] where employees.firstname=@fname and 
    employees.lastname=@lname;
end

enter image description here

  • Create a pipeline and parameters for fname and lname with default value like below.

enter image description here

  • Now create a copy activity and give the SQL table as source and follow below steps.

enter image description here

  • Give your sink dataset and my case sink is csv file in blob.
  • Now, execute pipeline and give the fname and lname parameter values.

enter image description here

  • Click on ok and you can copy the selected data from the query in the database to your sink.

My Output:

enter image description here

Upvotes: 1

Related Questions