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
 Old Forums
 CLOSED - General SQL Server
 Update Table Issue

Author  Topic 

Krilyn
Starting Member

7 Posts

Posted - 2006-06-13 : 11:07:08
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

22859 Posts

Posted - 2006-06-13 : 11:18:33
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 - 2006-06-13 : 11:22:41
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
   

- Advertisement -