cancel
Showing results for 
Search instead for 
Did you mean: 

Merge Collections based on Key Field

ChrisHodgson1
Level 4
Hi, I'm looking to merge two collections with different columns that have one column with data that will match between them. Looping through both into a new collection does work, but takes far too long with collections that have 1000+ lines. Is there a way of merging them in a way similar to a SQL "Join" query? If so, does anybody have any example code? Thanks in advance, Chris
12 REPLIES 12

StuartRedmore
Level 3
Hi Chris, I have attached it. The parameters are: In : Collection_One - Datatable In : Field_One_Name - String In : Collection_two - Datatable In : Field_Two_Name - String Out : Collection_Out - Datatable Out : DataTableLen - Decimal Naturally Datatables are the collections. The code I've written is basically the form of ""Left join"" , but it wouldn't be difficult to change to an inner join if that's what you needed. It only works on a single column to column relationship, these being Field_One_Name ( this must exist in Collection_One ), and Field_Two_Name ( this must exist in Collection_Two ).  but again it wouldn't take much work to expand this. You can ignore / remove the DataTableLen item from the code and output, I added it whilst debugging and simply forgot to remove it. Please let me know if i can help further.  

ChrisHodgson1
Level 4
Hi Stuart, That object worked perfectly! Thank you very much for your help I really appreciate it. Chris

Can you pls help me with the same code as well

------------------------------
Saumya Sinha
------------------------------