MySQL Forums
Forum List  »  Stored Procedures

Re: Parameters for table, field and searchValue
Posted by: Russel James
Date: October 14, 2015 02:45PM

OK, I think I'm almost there....

Here is my sproc.

PROCEDURE `usp_CheckForValue`(IN p_tbl varchar(50), IN p_fld varchar(50), IN p_searchValue varchar(50))
BEGIN
SET @t = p_tbl;
SET @f = p_fld;
SET @search = p_searchValue;

SET @s = CONCAT("SELECT ", @f, " FROM ", @t, " WHERE ", @f, " = ", @search);
PREPARE stmt FROM @s;
EXECUTE stmt;

END

I am looking up a table called "species" and a field called "speciesID" and looking for "COD"
CALL usp_SearchForValue("Species", "SpeciesID", "COD")

I get error message:
Error Code: 1054. Unknown column 'COD' in 'where clause' 0.000 sec

It's too literal this time !!

Can you advise ?

Thanks.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: Parameters for table, field and searchValue
940
October 14, 2015 02:45PM


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.