SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 update a table with new data ; help please
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sebastian11c
Posting Yak Master

125 Posts

Posted - 04/30/2012 :  18:37:42  Show Profile  Reply with Quote
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

Edited by - sebastian11c on 04/30/2012 18:55:45

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 04/30/2012 :  18:38:29  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
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

125 Posts

Posted - 04/30/2012 :  18:56:19  Show Profile  Reply with Quote
i dont get it;; what does it mean?

thanks for your reply
Go to Top of Page

yosiasz
Flowing Fount of Yak Knowledge

USA
1608 Posts

Posted - 04/30/2012 :  19:17:25  Show Profile  Click to see yosiasz's MSN Messenger address  Reply with Quote
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
Flowing Fount of Yak Knowledge

USA
1202 Posts

Posted - 04/30/2012 :  21:08:19  Show Profile  Reply with Quote
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

125 Posts

Posted - 05/04/2012 :  11:40:50  Show Profile  Reply with Quote
thanks every one
for your help
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000