Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear friends,

I have pivot table.. how to execute in codeigniter Modal:
SQL
SELECT CONCAT(
    'SELECT `ci`.item_id,`ci`.itemName,`ci`.order_date', GROUP_CONCAT('
     ,    `t_', REPLACE(Outlet_name, '`', '``'), '`.QtyRequested
         AS `', REPLACE(Outlet_name, '`', '``'), '`'
     SEPARATOR ''),
 ' FROM `chef_comp_items` as ci ', GROUP_CONCAT('
     LEFT JOIN `chef_comp_items`  AS `t_', REPLACE(Outlet_name, '`', '``'), '`
            ON `ci`.item_id = `t_', REPLACE(Outlet_name, '`', '``'), '`.item_id
           AND `t_', REPLACE(Outlet_name, '`', '``'), '`.Outlet_name = ', QUOTE(Outlet_name)
     SEPARATOR ''),
 ' GROUP BY `ci`.item_id'
) INTO @qry FROM (SELECT DISTINCT Outlet_name FROM `chef_comp_items`) t;

PREPARE stmt FROM @qry;
EXECUTE stmt;
Posted
Updated 3-Feb-16 3:43am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900