I've got a stored procedure that accepts batches of product info. For each product, either insert it into the DB or Update it, if it already exists.
A product is defined by a composite key -> ProductCompanyId
(where the product came from) and a ProductId
(the unique Id, per company).
I'm trying to do a MERGE
query. It works perfectly, until the batch has the same composite key in it more than once.
For example, lets imagine I have 10 products. 2 of these have the same comp-keys but different prices.
I thought the first 'row' would be inserted, with the 2nd row being an update.
Here is some FULL REPO sql code to show you what I've done.
It's far too hard to try and make sure there's only unique composite key's per batch. So, is there anything I can do?
I'm using SQL Server 2012 .. so I'm not sure if that's an issue.