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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Suggestion Please

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 table1
2.select * from table2 where table1.field1 and table1.field2
3.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 recommended
will this work for you:

select t1.*, t2.*
into table3
from MyTable1 t1 inner join MyTable2 t2 on t1.field1 = t2.field2
--or
insert 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.field2

look up that syntax in sql server help = books online = BOL

Go with the flow & have fun! Else fight the flow
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-02-03 : 08:49:41
insert into table2 select field1,...fieldn from Table1 where some conditions

Madhivanan
Go to Top of Page
   

- Advertisement -