0
Good morning
I need to do a Store Procedure where I need to do an Insert but I need to pull data from another table to include this Insert.
Example:
'''CREATE PROCEDURE SP_Corrige_Parcelas(@idPagamentoVenda int,@qtParcelas int,@prTaxaAdministracao numeric(9,2)
)
AS
BEGIN DECLARE @cont int DECLARE @idEmpresa int DECLARE @dtEmissao Date DECLARE @dtvenci Date DECLARE @vlParcela Numeric(9,2)
set @cont = 1
SELECT card.tbPagamentoVenda.idEmpresa, card.tbPagamentoVenda.dtEmissao , card.tbPagamentoVenda.vlPagamento FROM card.tbPagamentoVenda WHERE card.tbPagamentoVenda.idFormaPackage = @idPagamentoVenda
WHILE @cont < @qtParcelas BEGIN
INSERT INTO card.tbParcela(idPagamentoVenda,
nrParcela,
idEmpresa,
dtEmissao,
dtVencimento,
vlParcela,
vlTaxaAdministracao,
dtPagamento,
vlPago,
idStatusParcela,
idMovimentoBanco)
VALUES(@idPagamentoVenda,
@cont,
card.tbPagamentoVenda.idEmpresa,
card.tbPagamentoVenda.dtEmissao,
DATEADD(MONTH,@cont,card.tbPagamentoVenda.dtEmissao),
card.tbPagamentoVenda.vlPagamento / @vlParcela,
(card.tbPagamentoVenda.vlPagamento * @prTaxaAdministracao)/100,
NULL,
NULL,
NULL,
NULL)
SET @cont = @cont + 1
END;
END;'''
Thanks this already.
I forgot to comment, but I have to merge with external data too.
– João Bosco
Use the UNION ALL
– Heitor Scalabrini