Created
November 20, 2018 10:39
-
-
Save DmitrySikorsky/90cfd050f177f39bcc1f983bf71f3c62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE PROCEDURE [dbo].[UpdateChildItems] | |
| @ParentItemId INT, | |
| @ChildItems ChildItemsType READONLY | |
| AS | |
| BEGIN | |
| MERGE ChildItems AS t | |
| USING (SELECT Id, ParentItemId, SomeProperty1, SomeProperty2, SomeProperty3 FROM @ChildItems) AS s | |
| ON t.Id = s.Id AND t.ParentItemId = s.ParentItemId | |
| WHEN MATCHED THEN | |
| UPDATE SET t.SomeProperty1 = s.SomeProperty1, t.SomeProperty2 = s.SomeProperty2, t.SomeProperty3 = s.SomeProperty3 | |
| WHEN NOT MATCHED BY TARGET THEN | |
| INSERT (ParentItemId, SomeProperty1, SomeProperty2, SomeProperty3) | |
| VALUES (s.ParentItemId, s.SomeProperty1, s.SomeProperty2, s.SomeProperty3) | |
| WHEN NOT MATCHED BY SOURCE AND t.ParentItemId = @ParentItemId THEN | |
| DELETE; | |
| END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment