The scenario... There are four records:
ID=123, ParentID=null, Name="Bob"
ID=1000, ParentID=123, Name="Bob"
ID=1001, ParentID=123, Name="Bob"
ID=1002, ParentID=123, Name="Bob"
The requirement is to update Name="Joe" where ID=123, and then cascade the changes to the children records. This could be done easily w/ the same proc that updates the parent, however in my situation that proc is being shared, so my solution is to make a new query that fetches the right info w/ a join and then updates:
SET
Field1 = parent.Field1,
Field2 = parent.Field2,
Field3 = parent.Field3
from ExampleTable children
inner join ExampleTable parent on parent.ID = children.ParentID
WHERE children.ParentID = @ParentID
No comments:
Post a Comment