Re: procedure with if
DELIMITER $$
CREATE PROCEDURE guardarConbp()
BEGIN
declare v_numcc varchar(6);
declare v_rutprov varchar(10);
declare v_serie VARCHAR(3);
declare v_fecha DATE;
declare v_monto int;
declare v_numcheq int;
declare v_nummov int;
declare v_numfact VARCHAR(9);
declare getConbp int DEFAULT 0;
declare nameColumn int = 0;
declare cursor_conbp cursor for select CONBP_NUMEROCC, CONBP_RUTPROV, CONBP_SERIE, CONBP_FECHA, CONBP_MONTO, CONBP_NUMCHEQ, CONBP_NUMMOV, CONBP_NUMFAC from tbl_conbp where `CONBP_MONTO` != 0;
declare continue handler for not found set getConbp=1;
open cursor_conbp;
getConbp : LOOP FETCH
cursor_conbp INTO v_numcc, v_rutprov, v_serie, v_fecha, v_monto, v_numcheq, v_nummov, v_numfact;
if getConbp = 1 then
if(cursor_conbp) then
INSERT INTO reg_conbp(`NEW_CONBP_NUMEROCC`, `NEW_CONBP_RUTPROV`, `NEW_CONBP_SERIE`, `NEW_CONBP_FECHA`, `NEW_CONBP_MONTO`, `NEW_CONBP_NUMCHEQ`, `NEW_CONBP_NUMMOV`, `NEW_CONBP_NUMFAC`) VALUES( v_numcc, v_rutprov, v_serie, v_fecha, v_monto, v_numcheq, v_nummov, v_numfact);
ELSE )
ALTER TABLE reg_conbp add concat_ws("",NEW_CONBP_FECHA,nameColumn) date, concat_ws("",NEW_CONBP_MONTO,nameColumn) integer;
UPDATE reg_conbp SET NEW_CONBP_FECHA = v_fecha and NEW_CONBP_MONTO = v_monto WHERE NEW_CONBP_RUTPROV = v_rutprov ;
nameColumn ++;
end if;
leave getConbp;
end if;
end loop getConbp;
close cursor_conbp;
END; $$
DELIMITER ;