954,560 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Simple insert in loop.

Hi all. I come from an MS SQL background and a newbie in MY SQL. Im trying to run a simple query to populate a table:

Declare @I As Int
     
Select @I = 1 

While (@I < 100)
Begin   
  Insert into tbWhatEva
     Select @I

Select @I = @I + 1         
End

Why is it so hard to populate arbitrary data in a loop? Please tell me where Im going wrong.

Thank you

Tower-Rounder
Newbie Poster
23 posts since Dec 2009
Reputation Points: 15
Solved Threads: 6
 

Does your table only have one column ? Did you try adding the column name to your insert query?

pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 

Hi pritaeas.

The porblem isnt the table structure. Its the loop. Ive just quoted MS SQL syntax as that's how to do it in MSSQL. I just want to run a simple insert query multiple times in a loop. Im now sure how to define the loop in a way that My SQL understands.

Thanks for the reply

Tower-Rounder
Newbie Poster
23 posts since Dec 2009
Reputation Points: 15
Solved Threads: 6
 
pritaeas
Posting Expert
Moderator
5,480 posts since Jul 2006
Reputation Points: 653
Solved Threads: 875
 
Tower-Rounder
Newbie Poster
23 posts since Dec 2009
Reputation Points: 15
Solved Threads: 6
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: