Merge DataTable
Merges two DataTables by combining their rows and columns. This operation uses .NET's DataTable.Merge() method, which intelligently combines table structures and data based on matching schemas.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Input
- First Table - First DataTable to merge (base table)
- Second Table - Second DataTable to merge into the first table
Output
- Table - Merged DataTable containing combined data from both tables
Merge Behavior
The Merge operation follows these rules:
- Matching Columns: If both tables have columns with the same name, rows are combined
- New Columns: Columns from the second table that don't exist in the first table are added
- Row Addition: Rows from the second table are added to the first table
- Schema Combination: The output has all unique columns from both tables
This is different from Append DataTable which requires identical column structures.
Example Usage
Merging Tables with Same Structure
// Table 1: ["ID", "Name", "Email"]
// 3 rows
// Table 2: ["ID", "Name", "Email"]
// 2 rows
// Result: Table with ["ID", "Name", "Email"]
// 5 rows total (3 + 2)
Merging Tables with Different Columns
// Table 1:
// Columns: ["ID", "Name", "Email"]
// Row 0: ID=1, Name="John", Email="john@example.com"
// Row 1: ID=2, Name="Jane", Email="jane@example.com"
// Table 2:
// Columns: ["ID", "Phone", "Address"]
// Row 0: ID=1, Phone="555-1234", Address="123 Main St"
// Row 1: ID=3, Phone="555-5678", Address="456 Oak Ave"
// Result:
// Columns: ["ID", "Name", "Email", "Phone", "Address"]
// Row 0: ID=1, Name="John", Email="john@example.com", Phone="", Address=""
// Row 1: ID=2, Name="Jane", Email="jane@example.com", Phone="", Address=""
// Row 2: ID=1, Phone="555-1234", Address="123 Main St", Name="", Email=""
// Row 3: ID=3, Phone="555-5678", Address="456 Oak Ave", Name="", Email=""
Combining Data from Multiple Sources
// Customer data from CRM system
// Table 1: ["CustomerID", "Name", "Email"]
// 500 customers
// Purchase history from billing system
// Table 2: ["CustomerID", "TotalPurchases", "LastOrderDate"]
// 300 customers (not all customers have made purchases)
// Merged result contains all columns and all customer records
Adding Supplementary Information
// Base employee table
// Columns: ["EmployeeID", "Name", "Department"]
// Additional details table
// Columns: ["EmployeeID", "Phone", "Extension", "Location"]
// Merge to get complete employee information
// Result has all 6 columns
Enriching Data
// Product catalog
// Table 1: ["SKU", "ProductName", "Category"]
// Inventory data
// Table 2: ["SKU", "Stock", "Warehouse", "ReorderPoint"]
// Merged table has complete product information
// Columns: ["SKU", "ProductName", "Category", "Stock", "Warehouse", "ReorderPoint"]
Tips
- Merge combines both schema (columns) and data (rows)
- Unlike Append, tables don't need identical column structures
- New columns are added automatically
- Rows from both tables are preserved
- Missing values in new columns are filled with empty/null values
- Original tables remain unchanged
- Use Merge when combining tables with different but related schemas
- Use Append when stacking identical tables vertically
Common Errors
Empty First Table Error
Error: First table cannot be empty. Please provide a valid DataTable.
Solution: Ensure the first table input contains a valid DataTable object.
// Wrong
var firstTable = null;
// Correct
var firstTable = /* Valid DataTable */;
Empty Second Table Error
Error: Second table cannot be empty. Please provide a valid DataTable.
Solution: Ensure the second table input contains a valid DataTable object.
// Wrong
var secondTable = null;
// Correct
var secondTable = /* Valid DataTable */;
Merge vs Append
Understanding the difference:
Merge DataTable
- Purpose: Combine tables with different or similar structures
- Column handling: Adds new columns from second table
- Use when: Tables have different schemas but related data
- Result columns: Union of all columns from both tables
- Example: Combining customer details with purchase history
Append DataTable
- Purpose: Stack rows from tables with identical structure
- Column handling: Requires matching columns
- Use when: Tables have identical schemas
- Result columns: Same as input tables
- Example: Combining January and February sales data
Quick Comparison
// Scenario 1: Same structure - Use Append
// Table 1: ["Name", "Age"]
// Table 2: ["Name", "Age"]
// Append Result: ["Name", "Age"] with combined rows
// Scenario 2: Different structure - Use Merge
// Table 1: ["Name", "Age"]
// Table 2: ["Name", "Email"]
// Merge Result: ["Name", "Age", "Email"] with combined rows
Advanced Usage
Multi-Table Merge
// Merge multiple tables sequentially
var result = /* First table */;
// Merge second table
// First Table: result
// Second Table: table2
// Output: result
// Merge third table
// First Table: result
// Second Table: table3
// Output: result
// Final result contains data from all tables
Conditional Merging
// Only merge if certain conditions are met
var shouldMerge = /* some condition */;
if (shouldMerge) {
// Merge DataTable node
var mergedTable = /* output */;
} else {
var mergedTable = firstTable; // Use only first table
}
See Also
- Append DataTable - Stack tables with same structure
- Add Column - Add single columns
- Add Row - Add single rows
- Filter DataTable - Filter before merging