Hello,
I'm trying to create some loops inside my sql statements for some data migration. I have setup the following SQL statement to test out my syntax but keep recieving errors. Here are the ones I tried:
Code:
USE favoriteagent;
SELECT @totrows := COUNT(Customerid) FROM agents;
SET @count := 0;
REPEAT
SELECT * FROM agents WHERE (Customerid = @count);
SET @count := (@count -1);
UNTIL (@count := 0) END REPEAT;
And:
Code:
USE favoriteagent;
SELECT @totrows := COUNT(Customerid) FROM agents;
SET @count := 0;
WHILE (@count < @totrows) DO
SELECT * FROM agents WHERE (Customerid = @count);
SET @count := (@count -1);
END WHILE;
Everytime I recieve the following errors:
(using repeat)
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'REPEAT
SELECT * FROM agents WHERE (Customerid = @count)' at line 1
(useing while)
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHILE (@count < @totrows) DO
SELECT * FROM agents WHERE (Customerid = @count)' at line 1
How I do a loop?
Thanks in advance.