Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
MERGE Syntax
Message
De
19/01/2017 08:38:20
 
 
À
19/01/2017 07:11:15
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:
01646848
Vues:
33
>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)
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform