Ya lo resolví, me quedo así.
Código SQL
[-]alter procedure Nueva_BajaIns
@CodSAF varchar(4),
@CodIns varchar(5),
@Cant int,
@Motivo char(2),
@Fecha datetime,
@Observ varchar(50)
AS
declare @errorvar int
set @errorvar = 0
declare @Total int
set @Total = 0
begin transaction
if exists(select * from Existencia where SAF=@CodSAF and INS=@CodIns)
begin
select @Total = Cant from Existencia where SAF=@CodSAF and INS=@CodIns
if(@Total >= @Cant)
begin
insert into Salidas (CodSAF, CodIns, Cant, Motivo, Fecha, Observ)
values (@CodSAF, @CodIns, @Cant, @Motivo, @Fecha, @Observ)
set @errorvar = @errorvar + @@ERROR
if(@Total > @Cant)
begin
update Existencia
set Cant = Cant - @Cant
where SAF=@CodSAF and INS=@CodIns
set @errorvar = @errorvar + @@ERROR
end
else
begin
delete from Existencia
where SAF=@CodSAF and INS=@CodIns
set @errorvar = @errorvar + @@ERROR
end
end
end
if (@errorvar = 0)
commit transaction
else
rollback transaction
Muchas gracias de todos modos !!!
Salu2,
Ledian.