Jump to content

stored procedure cursor set in an if ???


minus4

Recommended Posts

hi there, i have the need to run 2 different SQL statements depending on what info i receive, i have put together an example stored procedure that errors on the DECLARE cur1 line.

 

DELIMITER $$

DROP PROCEDURE IF EXISTS sp_TEST $$

CREATE PROCEDURE sp_TEST(IN tester INT)
BEGIN


DECLARE done INT DEFAULT 0;
DECLARE prodid INT DEFAULT 0;
DECLARE mysql TEXT;

IF (tester=1) THEN
DECLARE cur1 CURSOR FOR SELECT productId FROM products WHERE live=1; < -- ERROR HERE
ELSE
DECLARE cur1 CURSOR FOR SELECT productId FROM products WHERE live=0;
END IF;


DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;


OPEN cur1;
FETCH cur1 INTO prodid;
REPEAT

UNTIL done END REPEAT;
CLOSE cur1;


SELECT prodid;


END $$
DELIMITER ;

 

ERROR: you have an error in your sql syntax blah blah........... (1064)

please don't concentrate on what it delivers or what the procedure might do, the problem is with the IF statement.

 

Would appreciate your help if thats possible.

 

thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.