Daniel
Daniel

Reputation: 395

MySQL trying to do a loop procedure

I am trying to insert into a table by using a loop that looks at a view and inserts each row one by one, I am planning to add more conditions bust I cant get the procedure working.

This is what I have:

DROP PROCEDURE IF EXISTS looprow;
DELIMITER ;;
CREATE PROCEDURE looprow()
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE i INT DEFAULT 0;
SELECT COUNT(*) FROM Ordered_Students INTO n;
SET i=0;
WHILE i<n DO 
  INSERT INTO Project_Assigned(StudentID, Project_Title) SELECT (StudentID, Rank1) FROM Ordered_Students LIMIT i,1;
  SET i = i + 1;
END WHILE;
End;
;;
DELIMITER ;

CALL looprow();

And the view I'm taking from looks like this:

enter image description here

I am getting the error= 1241 operand should contain 1 column.

Thank you for your help.

Upvotes: 0

Views: 27

Answers (1)

P.Salmon
P.Salmon

Reputation: 17615

The brackets SELECT (StudentID, Rank1) are the problem - remove them.

Upvotes: 1

Related Questions