ADF using Parameterized Stored Procedure

Introduction

Here in this article, we are trying to demonstrate the Stored Procedure Activity of ADF and how we pass the parameters in it.

Hope it will be interesting.

Case Scenario

We have a table named [ProductInfo]. It contains all the product name.

 CREATE TABLE ProductInto

(

      ProductID   INT,

      ProductName VARCHAR(50)

)

GO

INSERT INTO ProductInto

VALUES(1, 'Tooth Past'),(2, 'Tooth Brush')

Now, we have another Table named [OrderInfo], contains all the order information.

CREATE TABLE OrderInfo

(

   OrderID              INT,

   ProductID            INT,

   Qty                  INT,

   Rate                 DECIMAL(18,2)

)

GO

INSERT INTO OrderInfo

VALUES(1, 1, 2, 50),

(1, 2, 1, 30),

(2, 1, 1, 50)

We are going to read one by one Product from our [ProductInfo] table, calculate the Order amount and insert records in [ProductWiseOrderAmount] Table.

Basically we are passing parameters in Stored Procedure Activity and the Stored procedure do the rest.

Here we are using three Activities from Azure ADF i.e. Lookup Activity, ForEach Loop Activity and Stored procedure activity.

Hope you understand the case scenario.

Stored Procedure Sample

Basically it’s a simple stored procedure mentioned bellow.

CREATE PROCEDURE CalculateOrderAmount

(

  @p_ProductID  INT

)

AS

BEGIN

      INSERT INTO ProductWiseOrderAmount

      SELECT x.ProductID,

             x.ProductName,

               SUM(x.Amount) AS TotalAmount

      FROM  (

                  SELECT a.ProductID,

                           b.ProductName,

                           (a.Qty * a.Rate) As Amount

                  FROM   OrderInfo AS a

                           INNER JOIN ProductInto b

                                     ON a.ProductID = b.ProductID

                   WHERE a.ProductID = @p_ProductID

              ) AS x

       GROUP BY x.ProductID,

                x.ProductName

END

GO

ADF Solution


Lookup Activity Configuration

 

ForEach Loop Activity Configuratio

 

Stored Procedure Activity Configuration

 


Output

 

 

 

 

Hope you like it.


Comments

Popular Posts

Working with Spark – Spark RDD

Activity Dependencies with Logical AND in ADF

Working with Python – Module