We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,220 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

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

2
Contributors
4
Replies
19 Hours
Discussion Span
1 Year Ago
Last Updated
7
Views
Question
Answered
Tower-Rounder
Newbie Poster
23 posts since Dec 2009
Reputation Points: 15
Solved Threads: 6
Skill Endorsements: 0

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

pritaeas
Posting Prodigy
Moderator
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86

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
Skill Endorsements: 0
pritaeas
Posting Prodigy
Moderator
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86
Tower-Rounder
Newbie Poster
23 posts since Dec 2009
Reputation Points: 15
Solved Threads: 6
Skill Endorsements: 0
Question Answered as of 1 Year Ago by pritaeas

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0778 seconds using 2.64MB