recursion - TSQL A recursive update? -


i'm wondering if exists recursive update in tsql (cte)

id  parentid value --  -------- ----- 1   null     0 2   1        0 3   2        0 4   3        0 5   4        0 6   5        0 

i possible update column value recursively using e.g cte id = 6 top row ?

yes, should be. msdn gives example:

use adventureworks; go directreports(employeeid, newvacationhours, employeelevel) (select e.employeeid, e.vacationhours, 1   humanresources.employee e   e.managerid = 12   union   select e.employeeid, e.vacationhours, employeelevel + 1   humanresources.employee e   join directreports d on e.managerid = d.employeeid ) update humanresources.employee set vacationhours = vacationhours * 1.25 humanresources.employee e join directreports d on e.employeeid = d.employeeid; 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -