I created a StoreProcedure named, CancelNote, which, by using cursors, returns the products to the stock, passes the status of the item to canceled. It is working, however, not setting the "status" value in the [status] column. If someone can help me!
This is the script I created:
execute sp_CancelarNota 200200
create procedure sp_CancelarNota(@notafiscal integer)
AS
DECLARE @DATA DATE
DECLARE @VALOR DECIMAL(10,2)
DECLARE @MAT INT
DECLARE @CB INT
DECLARE @QTDITEM DECIMAL(10,2)
DECLARE @STATUS CHAR(1)
DECLARE cVendas CURSOR
FAST_FORWARD
FOR SELECT DATA, VALOrNOTA, MAT FROM NOTaFISCAL
WHERE NUMNF = @notafiscal
OPEN cVendas
FETCH NEXT FROM cVendas INTO @DATA, @VALOR, @MAT
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE PRODUTO SET QTDeATUAL = QTDeATUAL+@QTDITEM
WHERE CB = @CB
FETCH NEXT FROM cVendas INTO @CB, @QTDITEM
END
DELETE FROM NOTaFISCAL WHERE
NOTaFISCAL.NUMNF = @notafiscal
DELETE FROM ITENsNOTA WHERE
ITENsNOTA.NUMNF = @notafiscal
INSERT INTO NOTaFISCAL (STATUS) WHERE NUMNF = 100100 VALUES('INATIVO');
CLOSE cVendas
DEALLOCATE cVendas