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.
| Author |
Topic |
|
quokwok
Starting Member
1 Post |
Posted - 2010-03-04 : 09:38:39
|
| Hi, I currently have for (int i = 1; i <= 10; i++) { myCommand.CommandText = "INSERT INTO Data_Table (myColumn) VALUES (" + i + ")"; myCommand.ExecuteNonQuery(); }but this requires many SQL queries. Is there a way to create single SQL query which does the same thing - i.e. a single SQL query with a loop and a variable, so I wouldn't need to have the loop in the programming language? |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-04 : 09:40:50
|
| [code]INSERT INTO Data_Table (myColumn) SELECT numberFROM master..spt_valuesWHERE type='p'AND number BETWEEN 1 AND 10[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-04 : 09:42:22
|
| Try thisinsert into data_table (mycolumn) select number from master..spt_valueswhere type='p' and number between 1 and 10MadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-03-04 : 09:43:02
|
MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-03-04 : 09:44:22
|
quote: Originally posted by madhivanan
MadhivananFailing to plan is Planning to fail
by 1 min 32s ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|