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
 Old Forums
 CLOSED - General SQL Server
 Update Table Issue
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Krilyn
Starting Member

7 Posts

Posted - 06/13/2006 :  11:07:08  Show Profile
Trying to update the value from table A with the value from table B

Update A
Set A.Value = B.Value
From B
Where B.PartNumber in (Select Distinct(PartNumber) from A)

Problem is they're getting updated with the same value instead of the matching value from b where the part numbers match. Any help would be greatly appreciated. Thanks.

Kristen
Test

United Kingdom
22403 Posts

Posted - 06/13/2006 :  11:18:33  Show Profile
Your syntax will join every row in A with every row in B - and only the last one will be retained, hence it looks like you are getting only a single value.

I suspect what you are after is:

Update A
Set A.Value = B.Value
From TABLE_A AS A
     JOIN TABLE_B AS B
         ON B.PartNumber= A.PartNumber
Where B.PartNumber in (Select Distinct(PartNumber) from A)

Kristen
Go to Top of Page

Krilyn
Starting Member

7 Posts

Posted - 06/13/2006 :  11:22:41  Show Profile
Thank you. For the life of me I couldn't remember how I got it the first time. Thanks again.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000