MySQL Forums
Forum List  »  Stored Procedures

StoreProc to dynamically set table name
Posted by: Sinil Devassy
Date: December 30, 2011 07:49AM

Hi,


I have a mysql DB in which, the tablename I want to query is listed in another table. That means, first I need to query a table to find the tablename. Then later use that tablename.

I am not so good in MySQL. Still, I tried to wrote a procedure.

I didn't find any error, when I created the procudure. But, when I try to call, it fails:

call getTCs_cts('Service Activation','/MSW/MSW.cts');

"Table 'AppAuto_New.tpTBName' doesn't exist".

tpTBName is a variable. That means the variable is not replaced with the table name, while execution.

Can someone please help? Last two days, I spent a lot of time resolving this. I tried a lot of Internet help, but couldn't succeed. Can some MYSQL experts help me on this.

======================PROCEDURE START==========================
DELIMITER //
CREATE PROCEDURE getTCs_cts(
IN prj VARCHAR(100),
IN cts VARCHAR(100)
)
BEGIN

DECLARE tpTBName VARCHAR(20);
DECLARE tpID INT DEFAULT 6;
DECLARE tcTBName VARCHAR(20);

Select TestPlanTbName from Project where ProjectName = prj into tpTBName;
Select TestCaseTbName from Project where ProjectName = prj into tcTBName;

Select TP_ID from tpTBName where CTS = cts into tpID;
Select * from tcTBName where TP_ID = tpID;

END //
DELIMITER ;

======================END==========================

Thanks in advance,
Sinil

Options: ReplyQuote


Subject
Views
Written By
Posted
StoreProc to dynamically set table name
2303
December 30, 2011 07:49AM


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.