Let me start by saying that I am very new when it comes to SQL, but I picked it up pretty quickly. I am using SQL Server.
What I need to do is insert several records from another table and, where there is a duplicate, update the current record from the same table instead.
Naked with me:
I found some useful answers on this site, but no one works for me. Everyone returns a syntax error, and I'm not sure if this is just the interface that I use that does not support these commands or what. Inserting to where there is no duplicate key, this request works fine. If anyone could help me, what syntax could be used to correctly execute these commands with the given, I would be incredibly grateful!
Here are the ones that seem to be doing exactly what I need, but didn't work.
REPLACE INTO
INSERT ... ON DUPLICATE KEY UPDATE
INSERT OR REPLACE INTO
Here's an example of what my INSERT query looks like:
USE database
GO
INSERT INTO products
(upc, name, price)
select upc = TempTables.dbo.new_items.upc,
name = TempTables.dbo.new_items.name,
price = TempTables.dbo.new_items.price
FROM TempTables.dbo.new_items
source
share