user3300467
user3300467

Reputation: 15

Condition failing for one of the clauses in a 'case' statement

DELIMITER $$

USE `mg_ims`$$

DROP PROCEDURE IF EXISTS `sp_get_drop_down_data`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_get_drop_down_data`(

IN _name VARCHAR(15))

BEGIN

        CASE  

            WHEN _name = 'CUSTOMERS' THEN      

                SELECT cust_id,cust_name,address FROM tb_customers; 

            WHEN _name = 'SUPPLIERS' THEN      

                SELECT supp_name FROM tb_suppliers;

            WHEN _name = 'BRANDS' THEN 

                SELECT b.name FROM tb_brands b;

            WHEN _name = 'REGIONAL_OFFICES' THEN 

                SELECT r.name FROM tb_area_offices r;

            WHEN _name = 'SUB_OFFICES' THEN 

                SELECT s.name FROM tb_locations s;

            ELSE 

                SELECT 404 `Code`,'Case not Found' Description; 

        END CASE; 

    END$$


DELIMITER ;

All the above cases are working properly except 'regional_offices'... Although the syntax and logic is correct...

Upvotes: 0

Views: 32

Answers (1)

Simon MᶜKenzie
Simon MᶜKenzie

Reputation: 8674

Your problem is that _name is a varchar(15), but the string 'REGIONAL_OFFICES' is 16 characters long!

Upvotes: 1

Related Questions