Quizas este codigo te pudiera servir
if @transaction_type in ('A','U') and @object_type = 18
begin
Declare @Duplicada INT
set @Duplicada = (select TU CAMPO A COMPARAR from LA TABLA where DocEntry = @list_of_cols_val_tab_del)
IF Exists (SELECT COUNT(TU CAMPO A COMPARAR) FROM TUTABLA WHERE TU CAMPO A COMPARAR= @Ref HAVING COUNT(TU CAMPO A COMPARAR) > '1')
begin
set @error =1
set @error_message ='Tu mensaje de error'
end
end
A mi me sirve para Ordenes de Venta