I have a SSIS workflow where I fill a SQL Server table (260 data rows). In this SSIS workflow I have also implemented a lookup that checks whether the original row has changed. If so it should update it in the SQL Server table via a stored procedure.
This is my stored procedure:
ALTER PROCEDURE [dbo].[Update_MC_Countries]
@alphacode3char NVARCHAR(10),
@alphacode NVARCHAR(10),
@numcode NVARCHAR(10),
@german NVARCHAR(150),
@english NVARCHAR(150),
@region NVARCHAR(10),
@qmr NVARCHAR(10)
AS
BEGIN
SET NOCOUNT ON;
UPDATE [dbo].[MasterData_EDL_MC_Countries]
SET [alphacode3char] = @alphacode3char,
[alphacode] = @alphacode,
[numcode] = @numcode,
[german] = @german,
[english] = @english,
[region] = @region,
[qmr] = @qmr
I get this error:
An OLE DB record is available.
Source: "Microsoft SQL Server Native Client 11.0"
Hresult: 0x80040E2F
Description: "Violation of PRIMARY KEY constraint 'PK_MasterData_EDL_MC_Countries'. Cannot insert duplicate key in object 'dbo.MasterData_EDL_MC_Countries'. The duplicate key value is (DEU).".
Why does the code want to insert this row instead of updating it?
I don't get it. Any help is appreciated!
@alphacode3char
contradicts the datatypeNVARCHAR(10)
. Your code should never lie or mislead. – SMor