Today we setup a merge statement in writing to SQL , we selected user statement
Now with adding 1 record we were able to write down our custom sql to merge successfully with custom validation
Question to Team ETL,
1. how to do optimise this better?
2. Do we split the logic into update separately ? or one script to update is fine
3. Is it better to do this via procedure , if yes how?
MERGE [items].[basecamp].[checklist_tasks] AS target
USING (
VALUES (?, ?, ?, ?)
) AS source (MasterTaskID, AssignedEmployeeID, DueDate, RecurrenceRuleID)
ON target.MasterTaskID = source.MasterTaskID
AND target.DueDate = source.DueDate
WHEN MATCHED AND target.Status = 'Not Started' THEN
UPDATE SET
AssignedEmployeeID = source.AssignedEmployeeID,
RecurrenceRuleID = source.RecurrenceRuleID,
Status = 'Not Started'
WHEN NOT MATCHED THEN
INSERT (MasterTaskID, AssignedEmployeeID, DueDate, Status, RecurrenceRuleID)
VALUES (source.MasterTaskID, source.AssignedEmployeeID, source.DueDate, 'Not Started', source.RecurrenceRuleID);