Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Records from a second table

Status
Not open for further replies.

jtarry

IS-IT--Management
Mar 10, 2010
22
GB
I have tables containing

supppart

supp spart sqty
0100 AAA 0
0200 AAA 0
0300 AAA 0
0100 BBB 0
0200 CCC 0

order

opart oqty
AAA 1
BBB 1
CCC 1

I wish to update first table to show

supp spart sqty
0100 AAA 1
0200 AAA 1
0200 AAA 1
0100 BBB 1
0200 CCC 1

If only one part record in first table I can update, mulitple entries I cant.

script I use is

update suppart
set sqty = (select sqty from suppart where spart = opart)
where spart = (select spart from suppart where spart = opart)

result I get

supp spart sqty
0100 AAA 0
0200 AAA 0
0200 AAA 0
0100 BBB 1
0200 CCC 1

Thanks

 
Code:
update suppart
   set sqty = t2.oqty
  from suppart t1
inner
  join [order] t2
    on t1.spart = t2.opart

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top