I have two IN variables into my MYSQL stored procedure. I pass one into a select statement and the value is taken in a temporary variable which is passed to the second SQL statement.
CREATE PROCEDURE `usp_mystoredproc`(IN sText varchar(25), IN myId int(21))
begin
set @myCid= ( SELECT tabId AS id
FROM table1
WHERE IFNULL(tabId , '') != '' and table1_id= myId);
SELECT searchItem
FROM table2
WHERE searchItem LIKE CONCAT(sText , '%') and table2_id = @myCid
LIMIT 15 ;
END
Now the issue is, in the above stored procedure, @myCid gets multiple values and it fails.
I need to get all those ids and pass them to the second SQL. How do I handle this?
Best Answer
Join table1 and table2. Something like:
Bottom line, you don't need the @myCid variable