I have a select to bring all the records that have been entered and I need to do a while to cycle through this select and give an insert in another temporary table. Only while is always bringing the last record
What could be wrong?
DECLARE @CONTADOR INT
DECLARE @CONTADORLOOP INT = 1
SELECT @CONTADOR = COUNT(*) FROM #tableConta
SELECT * FROM #tableConta
WHILE(@CONTADORLOOP IS NOT NULL AND @CONTADORLOOP <= @CONTADOR)
BEGIN
SELECT @EMP_VLR = EMPCOD, @PLANO_COD_RED = PLANOCODRED FROM #tableConta where PLANOCODRED = @P_PLANO_CTA_COD_RED
PRINT @EMP_VLR
--INSERT INTO #tableDebCred (TOTAL2, EMPCOD2, PLANOCODRED) VALUES (@VLRTOTAL2, @EMP_VLR, @PLANO_COD_RED)
SET @CONTADORLOOP = @CONTADORLOOP + 1
END
END