with temp as
(
select Id, UserId, OfficeID, RoleId, DeptId, IsDelete, IsEnd, ParentId
from [dbo].[DiGui_Demo]
where UserId =1 or OfficeID = 56 or DeptId = 77
union all
select  a.Id,  a.UserId,  a.OfficeID,  a.RoleId,  a.DeptId,  a.IsDelete,  a.IsEnd, a. ParentId
from [DiGui_Demo] a
inner join temp on a.[parentid] = temp.[Id]
)
select distinct * from temp where IsEnd = 1 

=====================================================

 
 
create proc proc_DeleteDict
(
@autoId int
)
as
 
begin
 
with TEC as
(
select * from OA_Dict where AutoId = @autoId
union all
select a.* from OA_Dict a inner join TEC b on a.ParentId = b.AutoId
 
)  
 
update OA_Dict set IsDelete = 1 where AutoId in 
(
 select autoid from TEC
 )
 

end

sql with递归的更多相关文章

  1. sql 树 递归

    sql 树 递归 with SubQuery(No,Name,ParentNo) as ( ' union all select A.No,A.Name,A.ParentNo from [Port_D ...

  2. SQL实现递归及存储过程中In()参数传递解决方案[转]

    SQL实现递归及存储过程中In()参数传递解决方案   1.SQL递归 在SQL Server中,我们可以利用表表达式来实现递归算法,一般用于阻止机构的加载及相关性处理.   -->实现: 假设 ...

  3. SQL实现递归及存储过程中 In() 参数传递解决方案

    1.SQL递归 在SQL Server中,我们可以利用表表达式来实现递归算法,一般用于阻止机构的加载及相关性处理. -->实现: 假设OrganiseUnit(组织机构表)中主要的三个字段为Or ...

  4. SQL With (递归CTE查询)

    指定临时命名的结果集,这些结果集称为公用表表达式 (CTE).该表达式源自简单查询,并且在单条 SELECT.INSERT.UPDATE 或 DELETE 语句的执行范围内定义.该子句也可用在 CRE ...

  5. SQL Server 递归

    SQL Server 没有类似于Oracle START WITH NAME='xx' CONNECT BY PRIOR ID=PARENT_ID这样的语句,但是可以通过自定义标准函数+With语句实 ...

  6. 求SQL语句递归的算法

    表结构是这样的 部门    上级部门    A           BB           CC           DA           AB           BC           C ...

  7. sql server递归日期

    在做项目任务时,需要将一个日期范围转换为日期表. 例如:日期范围(2017年01月21日~2017年02月20日).转换成一日为单位的日期表,如下. 2017-01-21 2017-01-22 201 ...

  8. sql server 递归汇总 按指定层级汇总

    每个地区递归层级可能不一致,数据表(table)存放最小层级地区 area --地区层级表 id name f_id leve 1 中国 0 1 2 湖北 1 2 3 武汉 2 3 ... --测试数 ...

  9. SqlServer里,一条sql进行递归删除

    Server 2005中提供了公用表表达式(CTE),使用CTE,可以使SQL语句的可维护性,同时,CTE要比表变量的效率高得多. 存储过程方法: create proc up_delete_ncla ...

  10. sql with 递归 查询特定区间日期

    declare @startDay smalldatetime ='2013-01-01'  ;with cte as(     select @startDay as d    union all  ...

随机推荐

  1. LeetCode 319

    Bulb Switcher There are n bulbs that are initially off. You first turn on all the bulbs. Then, you t ...

  2. Android布局中的空格以及占一个汉字宽度的空格的实现

    在Android布局中进行使用到空格,以便实现文字的对齐.那么在Android中如何表示一个空格呢? 空格:  窄空格:  一个汉字宽度的空格:   [用两个空格(  )占一个汉字的宽度时,两个空格比 ...

  3. android开发推荐书籍列表

    1.  <第一行android代码> 入门,简单易懂,全面. 2. << Android群英传 >> 特点:UI部分相当详细 3. <<深入理解Andr ...

  4. HttpClient(4.3.5) - HTTP Authentication

    HttpClient provides full support for authentication schemes defined by the HTTP standard specificati ...

  5. Git CMD - add: Record changes to the repository

    命令格式 git commit [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend] [--dry-run] [(-c ...

  6. SSIS_TXT有规则资料导入到EXCEL

    SSIS开发需要完全安装sqlserver.本次demo是sqlserver2008. 1.创建项目 2.解决方案打开如图所示. 3.拉取一个序列容器,一个数据流任务. 4.在数据流任务点击.拉取一个 ...

  7. abstract

    /// <summary> /// 抽象类不能被直接实例化 /// is a /// </summary> public abstract class BasePhone { ...

  8. Mingw64编译wxWidgets3.0.2常见错误

    使用Mingw64编译wxWidgets3.0.2,首先得下载wxMSW-Setup-3.0.2.exe(https://sourceforge.net/projects/wxwindows/file ...

  9. 关于C/C++中的位运算技巧

    本篇文章讲述在学习CSAPP位运算LAB时的一些心得. 移位运算的小技巧 C/C++对于移位运算具有不同的策略,对于无符号数,左右移位为逻辑移位,也就是直接移位:对于有符号数,采用算术移位的方式,即左 ...

  10. 布局—column(属性)

    column-width:||用来定义多列中每列的宽度,用像素表示column-count:||用来定义多列中的列数,用数字来表示1-10columns: 200px 2||列宽和列数column-g ...