Below code works perfectly without the create table statement. I have spent an hour just looking at this simple piece of code to find an error.
DELIMITER $$
USE `operations`$$
DROP PROCEDURE IF EXISTS `rc_pending_data_tat_proc`$$
CREATE PROCEDURE `rc_pending_data_tat_proc`()
BEGIN
(
CREATE TABLE rc_pending_tat_temp /*works fine when I remove this*/
SELECT IF(b.retailer IS NULL,a.retailer, b.retailer) AS Retailer,
(CASE
WHEN DATEDIFF(criteria_date,transaction_date)<=50
THEN '<=50'
WHEN DATEDIFF(criteria_date,transaction_date) <=70
THEN '<=70'
WHEN DATEDIFF(criteria_date,transaction_date) <=80
THEN '<=80'
WHEN DATEDIFF(criteria_date,transaction_date) <=90
THEN '<=90'
ELSE
'>90'
END) AS Pending_since
, COUNT(*) AS `count`, CURRENT_TIMESTAMP AS `date`
FROM `rc_pending_data` a
LEFT JOIN `rc_store_retailer_mapping` b
ON a.retailer=b.store_name
GROUP BY 1,2
);
END$$
DELIMITER ;
The error it gives is pretty standard one i.e.
Error Code: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'create table rc_pending_tat_temp SELECT IF(b.retailer IS NULL,a.retailer, b.ret' at line 4
Please remove the "(" after BEGIN and ")" after the GROUP BY 1,2 part of your stored procedure. I tried this without the starting and ending parenthesis and it worked for me.