首页 > 数据库 >sqlserver 循环 + 递归 修改 末节点 标识

sqlserver 循环 + 递归 修改 末节点 标识

时间:2023-08-29 19:35:27浏览次数:33  
标签:ParentCategriesID cnt temp 递归 sqlserver 标识 Categories id select

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

相关文章

  • SqlServer中查询数据库所有表及其数据总条数和占用空间
    1、查询某数据库中的所有数据表SELECTname数据表FROMsysobjectsWHERExtype='u'ORDERBYname2、查询某数据库中的所有数据表及其数据总条数SELECTa.name数据表,b.rows数据总条数FROMsysobjectsASaINNERJOINsysindexesASbONa.id=......
  • spring boot WebSocket @ServerEndpoint注解标识的class无法获取spring容器中的bean
    在@ServerEndpoint类中直接使用@Autowired注解注入Spring管理的bean可能不会成功,因为@ServerEndpoint并不受Spring容器的管理。通过创建一个静态的成员遍历属性和一个带有@Autowired注解的setter方法,你可以在类加载时将bean注入到静态属性中。但是,请注意这样做......
  • java实现的类似于sql join操作的工具类,通用递归,最低需要java8
    直接上代码,缺包的自行替换为自己项目中存在的importjava.util.ArrayList;importjava.util.Collection;importjava.util.HashMap;importjava.util.HashSet;importjava.util.List;importjava.util.Map;importjava.util.Set;importjava.util.function.BiConsumer;i......
  • 递归排序之快速排序(挖坑法)
    1#include<stdio.h>234unsignedcharstandard(unsignedchar*array,unsignedcharlow,unsignedcharhigh)5{6unsignedcharkey=array[low];7while(low<high)8{9while(low<high&&array[high]&g......
  • sqlserver 从数据源左侧截取到遇到特殊字符的最短的子字符串
    selectdbo.sjGetPreStr('1234^5*6/-33_','[]-_=+*&^')    ===>1234Createfunction[dbo].[sjGetPreStr](@strvarchar(1000),@pointArrvarchar(100))returnsvarchar(1000)asbegindeclare@resvarchar(1000)=''......
  • 递归与分治
    递归递归的基本思想是某个函数直接或者间接地调用自身,这样原问题的求解就转换为了许多性质相同但是规模更小的子问题。求解时只需要关注如何把原问题划分成符合条件的子问题,而不需要过分关注这个子问题是如何被解决的。递归代码最重要的两个特征:结束条件和自我调用。自我调用是......
  • 不用循环和递归判断值在数组中的索引
    ////数组集合string[]str=newstring[]{"a","b","c","d","e","f","g"};////要查找的字符串stringNum="c";////使用Linq查询,将索引和值查出来,////新建一个匿名类,属性包括aabool类型,和Index索引......
  • ubuntu15.04下用apache+iasp部署asp+mssqlserver运行环境
    最近由于工作需要,尝试了一下在linux下配置asp运行环境,耗时两周,在网上能找到的相关资料和软件都比较匮缺,特记录一下。一、硬件环境及操作系统windows2008+vm,win2008安装了sql2005作为数据库服务器,vm虚拟机安装ubuntu15.04用apache2.0.59+iasp2.1作为webserver二、ubuntu15.04安......
  • leetcode 题库994——bfs典型解法(队列+递归实现)
     classSolution:deforangesRotting(self,grid:list[list[int]])->int:m,n=len(grid),len(grid[0])queue,good=[],[]defbfs(queue,good,m,n,grid):times=0directions=[(-1,0),(1,0),(0,1),(0,-1)]......
  • LeetCode题库77.组合——dfs典型解法,递归+回溯+剪枝
     classSolution:defcombine(self,n:int,k:int):nums=[x+1forxinrange(n)]res,ans=[],[]defdfs(nums:list[int]):iflen(ans)==k:ans_copy=ans.copy()#复制,避免ans数组改变使res跟着改变......