Reputation: 1
so I just added a new column to a table and now i want to populate that column in the pre-existing rows. This my current query, but it keeps erroring, because its trying to insert into the first column of the table.
insert into Product_Database(UPC)
select u.UPC
from upc_temp u
join upc_temp_gers g on u.PartNumber = g.PartNumber
join Product_Database p on p.ITM_CD = g.ItemCode
where u.UPC is not null
and this is the error its returning
Cannot insert the value NULL into column 'ITM_CD'
Clearly i am not trying to insert into the 'ITM_CD' column. Just 'UPC'.
Any help would be greatly appreciated. Thanks!
Upvotes: 0
Views: 2056
Reputation: 1269503
Presumably the logic you want is:
update p
set UPC = u.UPC
from upc_temp u join
upc_temp_gers g
on u.PartNumber = g.PartNumber join
Product_Database p
on p.ITM_CD = g.ItemCode
where u.UPC is not null;
Upvotes: 0
Reputation: 31775
now i want to populate that column in the pre-existing rows.
After you add a new column to a table, you don't populate the new column for existing rows with an INSERT.
You do it with an UPDATE.
Upvotes: 3