2

I'm trying to do a simple update query and I'm getting this error:

The multi part identifier "customers.customer_name" could not be bound

Query:

Update Suppliers
Set City = (select s.city
 From suppliers AS s
 Where s.supplier_name = customers.customer_name)
Where Exists (select c.city
 From customers AS c
 Where c.customers_name = Suppliers.supplers_name)
Aaron Bertrand
182k28 gold badges407 silver badges626 bronze badges
asked Jul 7, 2015 at 21:08

1 Answer 1

1

Your syntax is slightly off. In SQL Server, here is how I would perform this update:

UPDATE s SET s.city = c.city
FROM dbo.Suppliers AS s
INNER JOIN dbo.Customers AS c
ON s.supplier_name = c.customer_name;

From my most popular answer on Stack Overflow.

Remember to always use the schema prefix and also it is often easier to just call those columns name instead of prefixing each with the table name.

answered Jul 8, 2015 at 0:33

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.