DECLARE @cnt INT = 0; WHILE @cnt < 27 BEGIN SET @cnt = @cnt + 1; PRINT @cnt; with temp (id,[Name],ParentCategriesID)as ( select id,[Name],ParentCategriesID from Categories where id=27 union all select a.id,a.[Name],a.ParentCategriesID from Categories a inner join temp on a.ParentCategriesID = temp.[id] ), lastNode as( select id from temp where id not in (select ParentCategriesID from Categories ) ) update Categories set HasNext=0 where id in (select * from lastNode) END
标签:ParentCategriesID,cnt,temp,递归,sqlserver,标识,Categories,id,select From: https://www.cnblogs.com/valeb/p/17665682.html