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
 updating /replacing contents of the table

Author  Topic 

smithani
Starting Member

42 Posts

Posted - 2007-06-11 : 16:54:35
Is it possible to do an update * where in we update all the contents of the table after selecting specific rows of the same table.

for ex:

create table #Result(rowid int identity(1,1),cust_no int,companyname varchar(100),address varchar(200),zip varchar(9));

insert into #Result(cust_no,companyname,address,zip)
where (customertype='r' and customer.comp_id ='11')
group by customer.cust_no, customer.company


select * from #Result where customerstatus='s';

after this i want to update/replace the #Result with whatever results I have from the select statment.

Thanks for your replies.


dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-06-11 : 16:56:15
(1) I dont see the column customerstatus in your #Result table.
(2) Can you explain in more detail "...with whatever results I have from the select statment"

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

smithani
Starting Member

42 Posts

Posted - 2007-06-11 : 16:59:01
I think I might have found the answer, I can just delete from the temp table the results I dont need,it will be equivalent to updating it with the rows I need.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-12 : 08:56:16
Thats not an update. It would be replace only

Madhivanan

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

smithani
Starting Member

42 Posts

Posted - 2007-06-12 : 11:10:57
[quote]Originally posted by madhivanan

Thats not an update. It would be replace only

Is there any other way, b'cos I tried to delete but it doesn't restore the seed values for identity fields.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-12 : 11:20:03
Instead of Deleting, truncate it

Truncate table tablename

and then insert data

Madhivanan

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

- Advertisement -