DELIMITER $$ CREATE OR REPLACE DEFINER=`vn-admin`@`localhost` PROCEDURE `vn`.`invoiceOutListByCompany`(vCompany INT, vStarted DATE, vEnded DATE) BEGIN SELECT c.socialName as RazonSocial, c.fi as NIF, io.ref as Factura, io.serial as Serie, io.issued as Fecha, io.amount as Importe, c.id as Id_Cliente, iot.taxableBase as Base, pgc.rate as Tipo, iot.vat as Cuota, pgc.name as Concepto FROM vn.invoiceOut io JOIN vn.invoiceOutTax iot ON iot.invoiceOutFk = io.id JOIN vn.client c ON c.id = io.clientFk JOIN vn.pgc ON pgc.code = iot.pgcFk WHERE io.companyFk = vCompany AND io.issued BETWEEN vStarted AND vEnded ORDER BY io.ref DESC; END$$ DELIMITER ;