Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

MySQL Loops

loop mysql

  • Please log in to reply
No replies to this topic

#1 reachpradeep

reachpradeep

    CC Regular

  • Just Joined
  • PipPipPip
  • 41 posts

Posted 04 March 2007 - 07:12 AM

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:

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:

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.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download