Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Loop for INSERT ? [ Fast reply please ]

Author  Topic 

jonas
Starting Member

6 Posts

Posted - 2008-06-23 : 10:15:09
Hi everyone
I want to know if it's possible to do a for/while-loop so i can use INSERT

Look:
I've this int [] test = new test[140];
But i need to insert for every value (140) a number
so normally it would be :
INSERT ... (case1, case2, case3 ...) value (test[1],test[2],test[3] ...)

But isn't there a way to it with a loop?
SOmething Like this ?

for( int i = 0 , i< 140, i++)  {
INSERT case[i] value test[i]
}


Thanks in advance

Jonas

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-23 : 10:22:19
you can use WHILE loop.look for syntax in books online
Go to Top of Page

sachinsamuel
Constraint Violating Yak Guru

383 Posts

Posted - 2008-06-23 : 10:24:36
Definitely yes. You can use while loop to achieve this.

Check books online for more information on this.

Don't sit back because of failure. It will come back to check if you still available. -- Binu
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-06-23 : 10:35:37
INSERT ... (case1, case2, case3 ...) value (test[1],test[2],test[3] ...)
GO 50000

will insert 50000 records for you.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

jonas
Starting Member

6 Posts

Posted - 2008-06-23 : 10:40:02
where i find those books/tuts?
i searched google and i didn't find =/

Thanks for the replys
Go to Top of Page

sachinsamuel
Constraint Violating Yak Guru

383 Posts

Posted - 2008-06-23 : 10:47:36
Books online comes with SQL Server installation.

Don't sit back because of failure. It will come back to check if you still available. -- Binu
Go to Top of Page

jonas
Starting Member

6 Posts

Posted - 2008-06-23 : 10:59:22
I searched abut 15 mins and i din't find anything that i cold use...
Btw i this is sql with JAVA not with php or what ever

Could somebody tell me link or what i've to do ??

Jonas
Go to Top of Page

sachinsamuel
Constraint Violating Yak Guru

383 Posts

Posted - 2008-06-23 : 12:38:47

To download books online
http://technet.microsoft.com/en-us/library/ms130214.aspx


To read online
http://msdn.microsoft.com/en-us/library/aa256841(SQL.80).aspx

To read abt while loop from books online
http://msdn.microsoft.com/en-us/library/ms178642.aspx

Don't sit back because of failure. It will come back to check if you still available. -- Binu
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-06-23 : 12:52:59
quote:
Originally posted by Peso

INSERT ... (case1, case2, case3 ...) value (test[1],test[2],test[3] ...)
GO 50000

will insert 50000 records for you.



E 12°55'05.25"
N 56°04'39.16"



Provided that OP uses SQL Server 2005/2008

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -