Categories
Database Development

Only return second result of mysql stored proc

Good morning. This is my first attempt at a stored proc and it works nicely. The only problem is stat it returns 2 reslults, the secon result is the one that i need to import into excell, or php. how di i limit this stored proc to only show the secon result or how can i call a stored proc and asking to only return second query?

DELIMITER $$

USE `pastel`$$

DROP PROCEDURE IF EXISTS `pivot_accmt`$$

CREATE DEFINER=`qadmin`@`%` PROCEDURE `pivot_accmt`(IN InvDate1 VARCHAR(255))
BEGIN
SET @@group_concat_max_len = 32000;
SET @sql = '';
SELECT
    @sql := CONCAT(@sql,IF(@sql='','',', '),temp.output)
FROM
(
    SELECT
      DISTINCT
        CONCAT(
         'MAX(IF(fulldate = ''',fulldate,''', InvTotExclDEx, 0)) AS ',
          '`',fulldate,'`'
        ) AS output
    FROM
        fullnoprod WHERE fullnoprod.`InvDate` >= InvDate1
        ORDER BY MONTH(InvDate),YEAR(InvDate)
) AS temp;
SET @sql = CONCAT('SELECT mainNAME

                    , Name,InvDate, ', @sql, ' 
                   FROM fullnoprod

                   where `InvDate` >= (''',InvDate1,''')
                    group by AutoIndex
                    order by InvDate
                   ');


PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
    END$$

DELIMITER ;

Leave a Reply

Your email address will not be published. Required fields are marked *