MySQL Forums
Forum List  »  Stored Procedures

Dynamic SQL: Add column from variable.
Posted by: Arch Nemesis
Date: January 07, 2012 01:15PM

Here is what I'm trying to do from within a stored procedure:

SET @c = code_val;

SET @s = CONCAT('ALTER TABLE MyDB.tmp_Totals ADD COLUMN ',@c,' varchar(4)');

PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

Executing the statements one at at time from the interactive mysql prompt works. However, when running the stored proc:

ERROR 1064 (42000): 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 'CALL varchar(4)' at line 1

Any ideas why this is failing?

Options: ReplyQuote


Subject
Views
Written By
Posted
Dynamic SQL: Add column from variable.
2528
January 07, 2012 01:15PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.