Link to home
Start Free TrialLog in
Avatar of BoggyBayouBoy
BoggyBayouBoy

asked on

Updating one table with values from another

I have the following sql statement and I get a "cannot be bound" error.

update Products
set a.sizeenglish= b.sizeenglish
from Products a , Conversions b
where b.sizedecimal= a.sizedecimal

the conversion table looks like this

1", 2.54
2 3/4", 5.625

the decimal sizes in my products table are already populated.
ASKER CERTIFIED SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is what I meant, and why I like Inner Join statement it makes the code
self-documenting, if you later have to go back and add a LEFT/RIGHT/FULL JOINs
to a third table, it will allow you not to get the mixed-join-types error, but both forms COMMAS and JOINS deliver the same result.
Your error "cannot be bound" is due to the alias your are updating Products and then in your from you have Products as a.. and yo do not need to use the alias in the set ...see set a.sizeenglish...see code :)
 

update a
set sizeenglish= b.sizeenglish
from Products a 
INNER JOIN  Conversions b 
ON b.sizedecimal= a.sizedecimal

Open in new window

Avatar of BoggyBayouBoy
BoggyBayouBoy

ASKER

Great!! thanks.