This way, if the corporate code already exists, the tran will rollback and the error - reported like you want. In a mean time, the proc will not even attempt any other operations, not even insert into CIM.IdentifiedObject. Basically, what you can do is take your original proc (not this version but the one earlier) and add the code displayed above under **begin tran;** line.
if exists (select * from cim.asset where corporatecode = @Corporatecode) begin set @ErrorMessage = 'Corporate Code ' + @Corporatecode + ' already exists.' raiserror(@ErrorMessage, 16, 1); end;
No one has followed this question yet.