Add columns with data to existing Datatable

HI,
I have a datatable dt1 with 2 columns and some rows of data. I have another datatable dt2 with more information (columns) for the initial records. I need to merge these two to one datatable, If I can somehow confirm ‘EmpName’ is unique/Primary Key.
I did a merge datatable and I got the below result. how do we get my expected result? Thanks.

Hi
Welcome back to uipath community
–hope these steps would help you resolve this
–lets take we have two datatable ready on hand named dt1 and dt2
–now use a build datatable activity where create a dattable with output datatable structure we need and get the output with a variable of type datatable named finaldt
–and now use a for each row loop and pass the dt1 as input and change the variable name from row to row1
–inside the loop use another for each row loop and mention the input as dt2 and change the variable name from row to row2
–so now inside the inner for each row loop use a if condition like this
row1(0).tostring.equals(row2(0).tostring)
if true it will go to THEN part where we can use a ADD DATA ROW activity where mention like this in ARRAYROW property {row1(0).tostring,row1(1).tostring,row2(1).tostring}
and in the datatable mention as finaldt, so this row will get added
–after this add data row use a BREAK activity so that it wont loop again and again

kindly try this and let know for any queries or clarification
Cheers @ebinsunny

Thank you @Palaniyappan, that solved it.
Just to clarify, is there a single step activity to merge them mentioning the common column or something?

Hi @ebinsunny,
Can you use the ADD Column activity to add the third column.

yah we can use JOIN DATATABLE activity but it might fail if the columns has same name in two of the datatable
MERGE DATATABLE wont work here
–ADD DATACOLUMN will work here but will go through the same step

Cheers @ebinsunny

Thank you

Thank you, i guess that will add the column, but to populate the rows, we need the loop mechanism as above.

@ebinsunny @Palaniyappan
Just to optimize the solution you can use Join Data table activity and use Left join and in condition give the common column name of table1 and table2.
You will get the result as you want, but with 1 additional column of name (renamed as Name_1 in output table), which you can delete using Remove Data column.

This will help when you have large data and it will take very less time comparatively!! :slight_smile:

Yes, this worked. And it will be faster as well. Thanks.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.