How to use Query If Else Condition on Azure Data Factory?

Viewed 3755

So I have a query to compare the data, I want to compare between two table using If Else Condition on Azure Data Factory.

So here are dummy example T-SQL for the condition

BEGIN
SET @sales_detail_row = (select count(*)
from schema_A.SALES_DETAIL
where transaction between '2021-04-01' and '2021-05-16')
 
SET @pf_sales_detail_row = (select count(*)
from schema_B.SALES_DETAIL
where transaction between '2021-04-01' and '2021-05-16');
 
if (@sales_detail_row=@pf_sales_detail_row)
then print 'SUCCESS'
else
'FAILED'
END

How to implement these query into If Else Condition on Azure Data Factory ?

From this Source, I don't really understand, because no explanation about the query method.

1 Answers
  1. You can declare two variables sales_detail_row and pf_sales_detail_row in ADF:

    enter image description here

  2. Use two lookup activities to exec SQL query.

     select count(*) as row_count from [dbo].[emp]
    

    enter image description here

  3. Use Set variable activity to assign value to variables. Add dynamic content @String(activity('Lookup1').output.firstRow.row_count).

    enter image description here

  4. In If condition, we can use expression

     @equals(variables('sales_detail_row'),variables('pf_sales_detail_row'))
    

    to compare whether two values are equal.

    enter image description here

Related