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)
 updating a table using 1query

Author  Topic 

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-03-26 : 02:38:27
i have 2 table
table :
id,col1,col2,col3,col4...,col10
and table2 which was imported from a file
id,col1,col2
and i wantto update all matching rows in table1 from table 2
where
table1.id=table2.id
table1.col3=table2.col1
table1.col7=table2.col2
how can i do this?
thnaksi n advance
peleg


Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-26 : 03:04:24
[code]update t1
set t1.col1 = t2.col1,
t1.col2 = t2.col2
from table1 t1 inner join table2 t2
on t1.id = t2.id
where t1.col1 <> t2.col1
or t1.col2 <> t2.col2[/code]



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-03-26 : 03:45:19
thnaks alot
i dont need this part
where t1.col1 <> t2.col1
or t1.col2 <> t2.col2
beacuse i want to update as is whithiguht checkign the dtat

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-26 : 04:52:41
Is this update going to be a one off things or you plan to run this regularly ? If you plan to run this regularly, it will be updating all records regardless of weather there are any changes or not.



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page

pelegk2
Aged Yak Warrior

723 Posts

Posted - 2006-03-26 : 05:35:54
why do u say that?

Israel -the best place to live in aftr heaven 9but no one wan't to go there so fast -:)
Go to Top of Page
   

- Advertisement -