I have the follow stored procedure:
ALTER PROCEDURE [dbo].[spUpdateOrInsert]
SET NOCOUNT ON;
IF EXISTS (select 1 from table1 where ID = @ID )
SET Value = @value
INSERT INTO table1 (ID, Value)
VALUES (@ID, @Value)
in additional I have a NON-Clustered Unique on the ID Column.
I wrapped the procedure by transaction and there is a IF clause that say if it's exists than update, else INSERT.
Now, when calling the procedure From time to timeת I'm getting an exception that say: can't insert duplicate value in to table1.