Link to home
Start Free TrialLog in
Avatar of portlight
portlightFlag for United States of America

asked on

Need to pull a logID and use it as a variable within storedProc

I need to be able to set the logID for a stored procedure. This works for selecting the correct log

SELECT l.logId
    FROM logs l WHERE l.details LIKE 'FCT%'

Open in new window


Now I need to take that logID and set it so that I can use it in a query such as

CREATE PROCEDURE reportLogName ()

    BEGIN


     SET @lgID = logID  SELECT * FROM logs l WHERE l.details LIKE 'FCT%';
     SET @s = CONCAT(             
     'select * from logs where logid =',@tbl);

      PREPARE stmt FROM @s;

         EXECUTE stmt;
      DEALLOCATE PREPARE stmt;
        END //

    DELIMITER ;

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial