How can I pass tablename as a parameter in MySQL stored procedure?

45 pts.
Tags:
Database programming
MySQL
MySQL Stored Procedures
SQL
SQL stored procedures
Stored Procedures
my SQL stored procedure is like this.... ALTER PROCEDURE [dbo].[Sp_InsertDataMaster] @_ImageID int, @_Stat bit, @_tablename nvarchar(200) AS begin declare @strTemp nvarchar(max) set @strTemp = 'Insert into ' + @_tablename + '(ImageID,Status) values ('+ convert(nvarchar(5),@_ImageID) +','+ CONVERT(nvarchar(1),@_Stat) +')' --print @strTemp exec(@strTemp) end I want this stored procedure in MYSQL.

Answer Wiki

Thanks. We'll let you know when a new response is added.

It would be something <b><i>similar</i></b> to this:

<pre>CREATE PROCEDURE test
( ImageID varchar(10),
Stat varchar(1),
tablename varchar(200))
BEGIN
SET @s = CONCAT(‘INSERT INTO ‘,tablename,’ (ImageId,Status) values (‘,ImageID,’,’,Stat,’)’)
PREPARE stmt FROM @s;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END;</pre>

(change data types as needed…)

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following