You need create your select statement using a variable and the do the
prepare statement;

Drop Procedure If Exists RankStock;
DELIMITER |
Create Procedure RankStock(IN TableNameIn CHAR(20),IN ColNameIn
CHAR(20))
begin
   Set @selStmt = Concat("Select ",ColNameIn," from ",TableNameIn,"
order by ",ColNameIn); 
   Prepare s1 from @selStmt;
   Execute s1;
   Deallocate Prepare s1;
END|
DELIMITER ;


Dan 

-----Original Message-----
From: mos [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 04, 2006 10:58 AM
To: mysql@lists.mysql.com
Subject: Stored Procedures Question

I have a dozen tables and I need to perform the same operations on them
so I thought I'd create a stored procedure and just pass the table name,
column name.

I was hoping it would take the parameters and substitute that in the
code. 
So it looks like this:

create procedure RankStock(IN TableNameIn CHAR(20),
                            IN ColNameIn   CHAR(20))
begin
   select ColNameIn from TableNameIn order by ColNameIn; end;

Of course this produces errors because it doesn't like the TableNameIn
in the select statement. So from all this I have to assume I can't build
a Select statement by using passed parameters. Is that right?

TIA
Mike 

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/[EMAIL PROTECTED]
----------------------------------------------------------
This email is intended only for the person or entity
to which it is addressed and may contain 
confidential information.  Any review, 
retransmission, dissemination or other use of, or 
taking of any action in reliance upon, this 
information by persons or entities other than the 
intended recipient is prohibited.  If you receive this 
e-mail in error, please contact the sender by 
replying to this e-mail and delete this e-mail and 
any attachments from all computers without 
reading or saving the same in any matter 
whatsoever.



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to