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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-02-03 : 08:21:24
|
| Som writes "Hi, I have 3 tables and i want to select all the rows from table1 and go to table2 with the where condition table1 values and get the result from table2 and go to table3 and insert the table1 and table2 values.In the query form...1.select * from table12.select * from table2 where table1.field1 and table1.field23.insert into table2 (field1,field2,field3...) values (table1.field1,table1.field,table2.field2...)I am using VB as front end to issue the sql query and save it in recordset and loop thru. but the quantity of sql data is huge. table1 gets 20,000 lines and table2 gets 12,000. when i loop thru to insert the values into table3..its really really slow. is it possible to loop thru this in sql using stored procedure...is it advisable to use sql for looping...or is there any other ways take care of the speed?? Thanks in advance." |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-02-03 : 08:35:24
|
looping in sql is not recommendedwill this work for you:select t1.*, t2.*into table3from MyTable1 t1 inner join MyTable2 t2 on t1.field1 = t2.field2--orinsert into MyTable3 (field1, field2, field3, field4, ....)select t1.field1, t1.field2, t2.field1, t2.field2, ....from MyTable1 t1 inner join MyTable2 t2 on t1.field1 = t2.field2look up that syntax in sql server help = books online = BOLGo with the flow & have fun! Else fight the flow |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-02-03 : 08:49:41
|
| insert into table2 select field1,...fieldn from Table1 where some conditionsMadhivanan |
 |
|
|
|
|
|
|
|