Dongbae Dongbae - 1 year ago 57
MySQL Question

Passing in table for a procedure

How can someone pass in a table into a procedure and then output the first names inside the table?


firstName | lastName

John, Smith
Joe, Smith
Stan, Smith

And then only John, Joe and Stan pops up? I'm trying to make something similar for my personal website.

Here is what I have for MySQL:

CREATE PROCEDURE 'test'.'returnFirstName' ()

Answer Source

Try this:

CREATE PROCEDURE `test`.`returnFirstName` ()
  SELECT firstName 
  FROM myTable

To pass a parameter look at this: use a variable for table name in mysql sproc

Execution SQL:

SELECT test.returnFirstName();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download