0
Galera created a Storeprocedure called, Cancelarnota, that through the use of cursors, back the products to the stock, pass the status of the item to canceled. This working, however, is not setting in the column [status] the value of "inactive". If anyone can help me!
This is the scrip 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
If the purpose is to update the STATUS field of the Notafiscal table, for the NUMNF = 100100, the command would not be INSERT but UPDATE.
– Homer Simpson
And truth is...!!!
– Brenin_rice
@Brenin_rice: In the ITENSNOTE table, what is the name of the column containing the product code? And what is the name of the column that contains the quantity of items sold, the product? // In the PRODUCT table which is the name of the column containing the product code?
– José Diz
ITENSNOTE the column and CB a FK. and the column name of items sold and Qtdevend. in the table PRODUCT the column and CB a PK.
– Brenin_rice