Is it possible to call a procedure within an SQL statement?
        Posted  
        
            by darren
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by darren
        
        
        
        Published on 2010-03-20T19:02:44Z
        Indexed on 
            2010/03/20
            19:11 UTC
        
        
        Read the original article
        Hit count: 367
        
Hi everyone
I thought I would use a stored routine to clean up some of my more complex SQL statements. From what I've read, it seems impossible to use a stored procedure within an sql statement, and a stored function only returns a single value when what I need is a result set. I am using mySQL v5.0
SELECT p.`id`, gi.`id`
FROM `sport`.`players` AS p JOIN `sport`.`gameinstances` AS gi
ON p.`id` = gi.`playerid`                       
WHERE (p.`playerid` IN (CALL findPlayers`("Canada", "2002")))
    AND (gi.`instanceid` NOT IN (CALL findGameInstances`("Canada", "2002")));
For example, the procedures 'findPlayers' and 'findGameInstances' are are stored routines that execute some SQL and return a result set. I would prefer not to include their code directly within the statement above.
© Stack Overflow or respective owner