Reputation: 395
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:
I am getting the error= 1241 operand should contain 1 column.
Thank you for your help.
Upvotes: 0
Views: 27
Reputation: 17615
The brackets SELECT (StudentID, Rank1) are the problem - remove them.
Upvotes: 1