Join datatable activity error

When joining two DataTables in UiPath, the values from the second DataTable are being printed after the last row of the first DataTable.
errordt

@chandrakala.productanalys
Use Merge Datable and check Once

Well it’s because the two DataTables do not have the same columns.
Make sure that the two DataTables have the same columns.

when you join two DataTables, the result is typically a new DataTable that contains the combined data from both source DataTables. The order of rows in the resulting DataTable can depend on the join operation you performed.

I think u would have used Full join as it Keep all rows from DataTable1 and DataTable2 , regardless of whether the join condition is met. Null values are added into the rows from both tables that don’t have a match.

Try with other join methods and make sure with above conditions of column order

https://docs.uipath.com/activities/other/latest/workflow/join-data-tables

Hope this clarifies
@chandrakala.productanalys

I have also double-checked that, but I’m still encountering the same error.

@chandrakala.productanalys
Try this steps once :

  1. Read the first DataTable (DT1) from a data source.
  2. Read the second DataTable (DT2) from another data source.
  3. Sort DT1 based on a specific column (e.g., Sort by an ID column).
  4. Sort DT2 based on the same column used in DT1 for consistency.
  5. Join DT1 and DT2 using the appropriate join type and condition.
  6. Use the “Output Data Table” activity to see the contents of the result DataTable.

There are common columns between the DataTables. I have attempted left, full, and inner joins, but I continue to encounter the same error

Hmm
Ok
They are common columns but are they in same order of columns

Double-check that the columns you are using for the join are correctly mapped between the two DataTables. Ensure that the common columns are of the same data type and have matching values for the join to work as expected.

@chandrakala.productanalys

image

it append below datatable1
it was working

@chandrakala.productanalys

use join datatable activity

type as inner join

image

cheers

I attempted to utilize the LINQ expression.
(
From a In dt_1
Join b In dt_2
On a("Logged ").toString Equals b(“Emp”).tostring
Select dt_3.Rows.Add ({a(“Logged”), b(“Emp No”)})
).copytodatatable

error:Assign: Input array is longer than the number of columns in this table.

This one also took a long time to run, possibly because the DataTable has many rows.

expression is returning more values than there are columns in the target DataTable.
Try to mention like this
(
From a In dt_1
Join b In dt_2
On a("Logged ").toString Equals b(“Emp”).tostring
Select {a(“Logged”), b(“Emp No”)}
).CopyToDataTable(dt_3)

@chandrakala.productanalys

@chandrakala.productanalys

in the above LINQ expression first you need to create a columns which you want using build datatable activity and make output as dt_3

cheers

Hi,

you can try this query.

(From a In dt_1.AsEnumerable()
Join b In dt_2.AsEnumerable()
On a.Field(Of String)(“Logged”).ToString() Equals b.Field(Of String)(“Emp”).ToString()
Select dt_3.Rows.Add({a(“Logged”), b(“Emp No”)})
).CopyToDataTable()

errordt

getting error

@chandrakala.productanalys

create a build datatable with the columns of both the datatables
finaldt=
dt.AsEnumerable.Select(Function(r,i) dt3.LoadDataRow((r.ItemArray.Concat(dt2.Rows(i).itemarray).ToArray),False)).copytodatatable

cheers

image
error like this

@chandrakala.productanalys

please check the number of columns in the datatable

as it showing that the adding values are more than the number of columns

cheers

@chandrakala.productanalys

We assume that you are interested on a Data Join and not on a Side-By-Side merge

When the Data Join Activity will not join data, which do have the same values within the Join Columns it can have the following reasons:

  • e.g. Spaces at the end
  • some missmatching datatype interpretations

We would recommend:

  • check and remove the relevant values and ensure that in Excel is not invisible char, blanks
  • try it again and when it fails then try it with smaller prepared test data alternates

With LINQ we do have another control over this, but then we should also use it e.g. by trimming the data like

changed to:

Build Datatable - dtJoin with columns:
loggen on, status, unit, place, dept

(From a In dt_1.AsEnumerable()
Join b In dt_2.AsEnumerable()
On a("logged on").toString.ToUpper.Trim Equals b("empno").tostring.ToUpper.Trim
Let ra = a.ItemArray.Concat(b.ItemArray.Skip(1)).toArray
Select r = dtJoin.Rows.Add(ra)).CopyToDataTable
  • we have implemented an inner join (referring to your excel screenshot)
  • we never should ommit the AsEnumerable()
  • we trimmed and harmonized to upper cases
  • we constructed an object array, has to match dtJoin structure

The nature of a join is about pairing all left rows together with all right rows matching the join condition expressed with the Operation

We assume, that this was not intended, as it would not join loggen on 123 with empno 123