When running the following in the Query builder I am getting the Error "Commands out of sync; you can't run this command now" Do you see an issues with my code?
DROP PROCEDURE IF EXISTS sp_DBR_empty_categories;
DELIMITER $$
CREATE PROCEDURE
sp_DBR_empty_categories
()
BEGIN
-- make a holder table
DROP TEMPORARY TABLE IF EXISTS report_category_output;
--
CREATE TEMPORARY TABLE report_category_output
SELECT category.id, category.name, category.externalId AS internal_id, updated_at
FROM category;
ALTER TABLE report_category_output ADD COLUMN count_child_cat INT(11) UNSIGNED DEFAULT 0, ADD COLUMN count_product INT(11) UNSIGNED DEFAULT 0, ADD INDEX(id) ;
-- product counts DROP TABLE IF EXISTS product_count; CREATE TEMPORARY TABLE product_count SELECT report_category_output.id, count(*) AS product_count FROM report_category_output INNER JOIN productCategory ON report_category_output.id=productCategory.categoryId GROUP BY report_category_output.id;
ALTER TABLE product_count ADD INDEX(id);
-- back update UPDATE report_category_output, product_count SET report_category_output.count_product=product_count.product_count WHERE report_category_output.id=product_count.id ;
-- category counts DROP TEMPORARY TABLE IF EXISTS cat_count ; CREATE TEMPORARY TABLE cat_count SELECT report_category_output.id, count(c2.id) AS cat_count FROM report_category_output INNER JOIN category ON report_category_output.id=category.id INNER JOIN category c2 ON c2.parentExternalid=category.externalId GROUP BY report_category_output.id ;
ALTER TABLE cat_count ADD INDEX(id);
-- back update UPDATE report_category_output, cat_count SET report_category_output.count_child_cat=cat_count.cat_count WHERE report_category_output.id=cat_count.id ;
-- output SELECT id AS category_id, name, internal_id, updated_at, count_child_cat, count_product FROM report_category_output WHERE (count_child_cat=0 AND count_product=0);
END $$ DELIMITER ; -- EOF sp_DBR_empty_categories.sql