Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MERGE Syntax
Message
De
19/01/2017 08:57:51
 
 
À
19/01/2017 08:38:20
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Versions des environnements
SQL Server:
SQL Server 2012
Divers
Thread ID:
01646827
Message ID:
01646849
Vues:
27
>>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform