Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MERGE Syntax
Message
From
19/01/2017 08:38:20
 
 
To
19/01/2017 07:11:15
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2012
Miscellaneous
Thread ID:
01646827
Message ID:
01646848
Views:
32
>To be honest, the merge was new to me when I implemented it (and I have not used it since) so I am unsure as to the reason for it being used.
>
>What would be the better/alternative way to do this?

The MERGE doesn't hurt anything, it's just not necessary if that block of code will only ever update rows in the BranchItems table.

A person would normally use MERGE if some of the "incoming" rows (in this case, the CTE) could post either updates or inserts to the target table. In this case, that wouldn't happen, so you could simply do an UPDATE, along these lines :
UPDATE dbo.BranchItems SET bri_qtyonhand = COALESCE(bri_qtyonhand,0) + ChangedQty
FROM dbo.BranchItems Trg
JOIN cteChanges  Src ON Trg.bri_pk = Src.iItemid
WHERE  Src.iItemTypId = '43' 
Again, the MERGE isn't harmful (maybe slight overkill)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform