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

Posted on 2013-12-17
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



     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;
        END //


Open in new window

Question by:portlight
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
LVL 43

Accepted Solution

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

		SELECT logID INTO @lgID FROM logs l WHERE l.details LIKE 'FCT%' LIMIT 1;
		SELECT * FROM logs WHERE logid = @lgID;
	END //

Open in new window


Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

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

When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
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…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

622 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