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 2008 Forums
 Transact-SQL (2008)
 update a table with new data ; help please

Author  Topic 

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-04-30 : 18:37:42
hi

i have a table called

"products "

idproduct -- name -- country -- code price
1 -- apple england 23 5
2 -- apple brazil 24 4
3 -- banana colombia 25 3
4 -- apple canada 26 7
5 -- cherry usa 27 10


and my dealer send me a new prices for apples

A TABLE CALLED "update_apple"

name -- country -- code price
apple england 23 7.5
apple brazil 24 8.2
apple canada 26 10.14


how could i update the prices for apples in my table products ( using the new prices in my other table "update_apples")



this is the result that i want in my table "products"

"products "

idproduct -- name -- country -- code price
1 -- apple england 23 7.5 (not 5)
2 -- apple brazil 24 8.2 (not 4)
3 -- banana colombia 25 3
4 -- apple canada 26 10.14 (not 7)
5 -- cherry usa 27 10


many many thanks for your help

any idea will be appreciate

kind regards

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-04-30 : 18:38:29
when is the test over?

<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-04-30 : 18:56:19
i dont get it;; what does it mean?

thanks for your reply
Go to Top of Page

yosiasz
Master Smack Fu Yak Hacker

1635 Posts

Posted - 2012-04-30 : 19:17:25
why do you have a column named countryid and corresponding foreign key to a country table?
can you please provide the data as follows for all data


declare @products table(idproduct int, name varchar(50), country varchar(50), code int, price decimal(10,3))
insert into @idproduct -- name -- country -- code price
1, 'apple', 'england', 23, 5
union etc



<><><><><><><><><><><><><><><><><>
If you don't have the passion to help people, you have no passion
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2012-04-30 : 21:08:19
update a
set a.price = b.price
from
products a
inner join
update_apple b
on a.name = b.name
and a.country = b.country
and a.code = b.code


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

sebastian11c
Posting Yak Master

129 Posts

Posted - 2012-05-04 : 11:40:50
thanks every one
for your help
Go to Top of Page
   

- Advertisement -