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)
 inserting one table data into another

Author  Topic 

Vishakha
Starting Member

40 Posts

Posted - 2006-06-01 : 06:52:06
It may be a very basic question, let me split it in 2 parts

1. My stored procedure has one temp table, I want to do some computation and create another table and put those values in that table
this is what i am doing

insert into table2
select col1, col2, col3
from table 1

where col1, col2 and col3 are computed values based on the values in the table 1.

How is this insert taking place, is it the batch mode, is there any more efficient way of doing this.

since the insert is based on the id field, is it possible to alter create the new columns in the table1, do the computation on the table 1 and insert the new field.

How will this approach work in terms of performance, please help

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-01 : 07:00:57
What type of computation?

Do you want to do something like this?

insert into table2(col1,col2,col3)
Select col1*34,col2,col1*10 -- or some other caluculations
from table1

Madhivanan

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

Vishakha
Starting Member

40 Posts

Posted - 2006-06-01 : 09:01:41
No I am doing computation like sum [col1_data], for all the users based on the uid.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-06-01 : 09:59:47
Do you want to copy the sums to other table?
Why cant you do this in select statement?

Select cols, sum(col) from...
group by cols

Madhivanan

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

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-06-01 : 10:09:12
Vishakha,

Please post some sample data & how do u want those to be inserted into the 2nd table (ie. expected results)

Srinika
Go to Top of Page
   

- Advertisement -