Reputation: 424
I am writting and update to my database, which i want to import but i do not know what is wrong with my code. MySQL Workbench and phpMyAdmin return me a syntax error. It is just an example case statement. Can anyone help me?
SET @company_code = 0;
SELECT @company_code := LOWER(`value`) FROM `settings` WHERE `setting_name` = 'COMPANY_CODE';
CREATE PROCEDURE p(in code varchar(200))
BEGIN
CASE code
WHEN 'first_company' THEN SELECT code;
ELSE SELECT '1';
END CASE
END;
CALL p(@company_code);
Can i do that without creating the procedure?
Upvotes: 1
Views: 754
Reputation: 272236
END
;
in order to create procedureSee Defining Stored Programs for explanation.
DELIMITER foo
CREATE PROCEDURE p(IN code VARCHAR(200))
BEGIN
CASE code
WHEN 'first_company' THEN INSERT INTO dest_first SELECT code, * FROM srctable;
ELSE INSERT INTO dest_other SELECT '1', * FROM srctable;
END CASE;
END;
foo
DELIMITER ;
SET @company_code = 0;
SELECT @company_code := LOWER(value) FROM settings WHERE setting_name = 'COMPANY_CODE';
CALL p(@company_code);
Upvotes: 1
Reputation: 2762
As per our discussion above, If "settings" table has the record with company_code = "first_company" then you want to insert the record then it can be achieved by this way
INSERT INTO colourmst (CODE, Column1)
SELECT LOWER(`value`) , 'XYZ'
FROM `settings` WHERE `setting_name` = 'COMPANY_CODE'
Upvotes: 0