MySQL Forums
Forum List  »  Stored Procedures

SUCCESS:Re: Can I use a parameter for a colum name ?
Posted by: Burt Stewart
Date: December 08, 2012 02:07PM

success (see sproc below)
So as Santa said "Yes Virginia, you CAN use a parameter for a colum name"

My errors were:
1. the CONCAT syntax, it needs the substrings separated by comma !
2. customerID is an int not a string

happy holidays to all


DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test_procedure`(IN ColumnNameParam varchar(10) )
BEGIN
set @ColumnName = ColumnNameParam;
set @s = CONCAT("UPDATE customer set ", @ColumnName, " = 'Test of ColumnNameParam' WHERE customer_id = ", 1);
PREPARE stmt FROM @s;
EXECUTE stmt;
END

Options: ReplyQuote


Subject
Views
Written By
Posted
SUCCESS:Re: Can I use a parameter for a colum name ?
1103
December 08, 2012 02:07PM


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.