minus4 Posted March 24, 2009 Share Posted March 24, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/150881-stored-procedure-cursor-set-in-an-if/ Share on other sites More sharing options...
fenway Posted March 27, 2009 Share Posted March 27, 2009 Drop the parens for the if... otherwise, it references the IF() function. Quote Link to comment https://forums.phpfreaks.com/topic/150881-stored-procedure-cursor-set-in-an-if/#findComment-795305 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.