Overview

INSERT/UPDATE in a Single Statement

DECLARE @UnitMeasureCode NCHAR(3) = 'ABC',
    @Name NVARCHAR(25) = 'Test Value';

UPDATE Production.UnitMeasure
SET [Name] = @Name
WHERE UnitMeasureCode = @UnitMeasureCode

-- Insert the row if the UPDATE statement failed.	
IF (@@ROWCOUNT = 0)
BEGIN
	INSERT INTO Production.UnitMeasure (UnitMeasureCode, Name)
	VALUES (@UnitMeasureCode, @Name)
END

INSERT/UPDATE using MERGE

DECLARE @UnitMeasureCode NCHAR(3) = 'ABC',
    @Name NVARCHAR(25) = 'Test Value';

MERGE TOP (100) Production.UnitMeasure AS [Tar]
USING (SELECT @UnitMeasureCode, @Name) AS [Src] ([UnitMeasureCode], [Name])
ON ([Tar].UnitMeasureCode = [Src].UnitMeasureCode)
WHEN MATCHED THEN
	UPDATE
		SET [Name] = [Src].[Name]
WHEN NOT MATCHED THEN
	INSERT 
	([UnitMeasureCode], [Name])
	VALUES ([Src].UnitMeasureCode, [Src].[Name])
WHEN NOT MATCHED BY SOURCE THEN
   DELETE;