I have a table structure with columns like this
The parents are contained in the same table, and i would like to populate the parent name column using a statement like:
UPDATE Table
SET ParentName = (select Name
from Table
where Id = ParentId)
When i do this, all the ParentNames are set to null. Thoughts?
I would go with the update from
statement.
UPDATE tb
SET
tb.ParentName = parent.Name
FROM Table tb
INNER JOIN Table parent ON parent.Id = tb.ParentId
This is T-SQL specific, but it should work pretty well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With