Page 1 of 1

variables in STORED PROCEDURES

Posted: Tue Oct 27, 2009 11:51 am
by kendall
I've Create a procedure taking a table name as a paramter....

I have the following procedure code snippet....
[sql]... DECLARE tablename VARCHAR(20);SET tablename = Table_Name;SELECT YEAR(RegDate) AS `Year`, QUARTER(RegDate) AS `Quarterly`, COUNT(`REGID`) AS NoIssueQuarterFROM tablenameWHERE .... /* Table_Name is the parameter while tablename is the variable */ [/sql]

However when I try to execute the procedure (Table_Name = 'debts') I get the error
SQL Error: Unknown column 'debts' in 'field list'
How do you pass the variable off as the table to be used in the SQL statement?