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 2005 Forums
 Transact-SQL (2005)
 UPDATE table with values from another table

Author  Topic 

Mondeo
Constraint Violating Yak Guru

287 Posts

Posted - 2008-05-20 : 06:42:49
Table 1

VehicleRef Term Mileage Price
12000 3 10000 212.12
12001 3 10000 215.12
12002 3 10000 217.12
12003 3 10000 220.20

Table 2

VehicleRef Term Mileage Price
12000 2 10000 121.12
12000 2 20000 123.12
12000 2 30000 145.12
12000 3 10000 145.12
12000 3 20000 145.12
12000 3 30000 146.45

I want to update the price on table 1 with the price from table2 where the vehicleref,term,mileage are the same in table1 and table 2

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-05-20 : 06:46:10
Don't you know this even after over 100 posts?

Update t1
set Price = t2.Price
From Table1 t1 join Table2 t2
on t1.VehicleRef = t2.VehicleRef
and t1.Term = t2.Term
and t1.Mileage = t2.Mileage


Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page
   

- Advertisement -