Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in Dynamic Query in Stored Procedure.Please Help.

Status
Not open for further replies.
Mar 15, 2007
1
IN
Hi All,

I have a problem with my MySQL Stored Procedure.
I am writing a SELECT query using dynamic table name.
For framing such dynamic queries, I need to use Prepared Statement and then EXECUTE it.

But to fetch the fields, when I try to DECLARE CURSOR. I am getting Syntax Error.
Can anynody tell me how to use CUSRSOR for Prepared Statement.

Below, is my sample code.

CREATE PROCEDURE `test`(IN argCaseid INT,IN argGroupid INT)
BEGIN
SET @priya=CONCAT("SELECT * FROM abc");
prepare st1 FROM @priya;
EXECUTE st1;
DECLARE curTroubleTicket CURSOR FOR st1;
OPEN curTroubleTicket;
troubleticketloop: LOOP
FETCH curTroubleTicket INTO strcase,strgrp,strok;
SELECT strcase;
LEAVE troubleticketloop;
END LOOP;
CLOSE curTroubleTicket;
END


Regards,
Priya
(priya_vasanthakumar@sifycorp.com)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top