Solved

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

Posted on 2013-12-17
1
295 Views
Last Modified: 2013-12-17
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

0
Comment
Question by:portlight
1 Comment
 
LVL 43

Accepted Solution

by:
Chris Stanyon earned 500 total points
ID: 39723838
You would use the SELECT...INTO syntax. Also, no need to prepare your Statement:

DELIMITER //
CREATE PROCEDURE reportLogName ()
	BEGIN
		SELECT logID INTO @lgID FROM logs l WHERE l.details LIKE 'FCT%' LIMIT 1;
		SELECT * FROM logs WHERE logid = @lgID;
	END //
DELIMITER ;

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question