Best way to check if a data exists in a data table?

I have 2 data table like this

image

I want to check if Emp Code in dt 1 exists in dt 2

What is the best way to achueve this?

Kindly help…

I want to check only the Emp Code so, I don’t want to check if the item array exists

@Palaniyappan @lakshman

1 Like

HI
use a FOR EACH ROW loop and pass dt1 as input and variable name from row to row1
–inside the loop use one more FOR EACH ROW loop and pass dt2 as input and variable name from row to row2
–inside the inner loop use a IF condition like thiis
row1(“Emp Code”).ToString.Equals(row2(“Emp Code”).ToString)
if true it will go to THEN part where we can use a writeline like
row1(0).tostring+"value exists in dt2"
and next to this writeline use a BREAK activity

Cheers @cybzom

Hi Cybzom,

This is also resolved using simple join query:
From e1 In emp1 Join e2 In emp2 On e1.emp_id Equals e2.emp_id Select New With {Key
.Emp_Name = e1.emp_name, Key
.Emp_Salary = e2.emp_salary
}

2 Likes

Hi @cybzom

You can make use of Lookup Datatable activity.

So by creating variable in rowIndex parameter of that activity, will help you to get rowIndex value (e.g 6 ) of that searched or lookup value in perticular column and if it is not there in that column, then it’ll give you rowIndex as -1. So by using this logic you’ll get to know the same.

2 Likes