Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MERGE Syntax
Message
From
19/01/2017 08:57:51
 
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Environment versions
SQL Server:
SQL Server 2012
Miscellaneous
Thread ID:
01646827
Message ID:
01646849
Views:
26
>>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)

Thanks for the clarification. As my memory about this returns, I think what the thinking was at the time was that I'd have one trigger for insert/update/delete but then I guess split it out into 3 separate ones and left the MERGE in.
Frank.

Frank Cazabon
Samaan Systems Ltd.
www.samaansystems.com
Previous
Reply
Map
View

Click here to load this message in the networking platform