Hi,
I have to update the column based on match and not match conditions
But Merge supports update only for Matched and not supported in not matched conditions
It shows error as 'Update not allowed when not mached'
Kindly share your solutions
Thanks
Rajkiran SwainPosted Apr 28, 2023, 10:48 AM
Tuhin PaulPosted Apr 30, 2023, 12:04 AM
Part 2
This MERGE statement will update the matching records and insert the non-matching records in a single query, which is more efficient than running two separate queries.
Tuhin PaulPosted Apr 30, 2023, 12:01 AM
The aliases used in the USING clause and INSERT statement should be more descriptive than s and t. This will make the code easier to read and understand. It is important to wrap both the MERGE statement and the UPDATE statement in a transaction to ensure that the two statements are executed atomically. If the default value used in the UPDATE statement ('default_value') is going to be changed frequently, it would be better to use a parameter instead of hard-coding the value in the SQL statement. Sharing a code based on the above: