Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-17
1
Medium Priority
?
305 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
[X]
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 44

Accepted Solution

by:
Chris Stanyon earned 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

688 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