SQL Merge success

More
11 months 2 weeks ago - 11 months 2 weeks ago #25461 by prashant
SQL Merge success was created by prashant
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);
 
Last edit: 11 months 2 weeks ago by prashant.
The following user(s) said Thank You: admin

Please Log in or Create an account to join the conversation.

More
11 months 2 weeks ago #25462 by admin
Replied by admin on topic SQL Merge success
For small datasets your solution is perfect. 
One script is always better than several

For large datasets loading data into staging table and than running the script will provide a better performance
 

Mike
ETL Architect
The following user(s) said Thank You: prashant

Please Log in or Create an account to join the conversation.

More
11 months 2 weeks ago #25464 by prashant
Replied by prashant on topic SQL Merge success

For large datasets loading data into staging table and than running the script will provide a better performance

Thank you , I will remember this for future projects :) 

Please Log in or Create an account to join the conversation.

Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Read more
Marketing
Set of techniques which have for object the commercial strategy and in particular the market study.
Google
Accept
Decline
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline
Google Analytics
Accept
Decline
Functional
Tools used to give you more features when navigating on the website, this can include social sharing.
Advertisement
If you accept, the ads on the page will be adapted to your preferences.
Google Ad
Accept
Decline
Save