variables in STORED PROCEDURES

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

variables in STORED PROCEDURES

Post 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?
Post Reply