T-SQL recursive query - how to do it?
You probably want to use a common table expression
which allows you to generate recursive queries.
eg:
;with cte as ( select * from yourtable where id=1 union all select t.* from cte inner join yourtable t on cte.id = t.parentid) update yourtable set userid = 101 where id in (select id from cte)