Doubt of how to make multiple inserts

0

I have a problem when I want to add a rent I want to generate several inserts to the payment table depending on the quantity and I do not know how to do it
Example

insert into Alquiler values('48265014',1000,1,getdate(),'19/11/2017',300.00, cantidad 3,1);
go

I want it to appear like this depending on the amount

insert into pagos values(1,300.00,'19/11/2017',0);
insert into pagos values(1,300.00,'19/12/2017',0);
insert into pagos values(1,300.00,'19/01/2018',0);
    
asked by Josue Almanza 20.10.2017 в 00:56
source

1 answer

0

What you should use in this case is a loop, while to be more precise. It would be as follows:

DECLARE @CONT AS INT;
SET @CONT = 0
WHILE @CONT < 7 -- controlas las cantidad de vueltas
BEGIN
insert into pagos values(1,300.00,'19/11/2017',0);
SET @CONT = @CONT + 1
END
    
answered by 20.10.2017 в 07:33