Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an item_data table with unique ID's 'item_id' which is a unique identifier column and item name. I have another table item_data_new with new ID's and the item name is the same as in table item_data. My aim is to update all the IDs of item in the item_data table with the id's of item_data_new where the item name matches. This code is written in T-SQL.The below code is giving error:
T1.item_id could not be bound.

What I have tried:

UPDATE item_data
SET T1.item_id= T2.item_id

FROM item_data T1 JOIN item_data_new T2
ON T1.name= T2.name
Posted
Updated 20-Sep-21 1:28am

The columns on the left-hand side of the assignment in an UPDATE can only refer to the table being updated, so you don't need to specify the table name or alias:
SQL
UPDATE T1
SET item_id = T2.item_id
FROM item_data As T1 
INNER JOIN item_data_new As T2
ON T1.name = T2.name;
UPDATE (Transact-SQL) - SQL Server | Microsoft Docs[^]
 
Share this answer
 
v2
T1 is not available as a pseudonym in the SET. Use the full table name instead:
SQL
UPDATE item_data
SET Item_Data.item_id= T2.item_id

FROM item_data T1 JOIN item_data_new T2
ON T1.name= T2.name
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900