CREATE PROCEDURE [dbo].[Update_Customers]
@tblCustomers CustomerType READONLY
AS
BEGIN
SET NOCOUNT ON;
--UPDATE EXISTING RECORDS
UPDATE Customers
SET Name = c2.Name
,Country = c2.Country
FROM Customers c1
INNER JOIN @tblCustomers c2
ON c1.CustomerId = c2.Id
--INSERT NON-EXISTING RECORDS
INSERT INTO Customers
SELECT Id, Name, Country
FROM @tblCustomers
WHERE Id NOT IN(SELECT CustomerId FROM Customers)
END
from : https://www.aspsnippets.com/Articles/SqlBulkCopy--Bulk-Insert-records-and-Update-existing-rows-if-record-exists-using-C-and-VBNet.aspx
沒有留言:
張貼留言