Hola amigos de este foro:
Tengo 2 tablas (Existencia y Salida)
Intento hacer un procedimiento almacenado donde se le de salida a un producto existente y cantidad.
Este es el código:
Código SQL
[-] create 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
@Total = select 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 -- realizo la resta para saber disponibilidad una vez hecha la salida
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
if (@errorvar = 0)
commit transaction
else
rollback transaction
Me da este error:
Cita:
Server: Msg 170, Level 15, State 1, Procedure Nueva_BajaIns, Line 26
Line 26: Incorrect syntax near '@Total'.
|
En espera de su ayuda y muchas gracias de antemano.
Salu2,
Ledian.