sql with递归
|
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递归的更多相关文章
- sql 树 递归
sql 树 递归 with SubQuery(No,Name,ParentNo) as ( ' union all select A.No,A.Name,A.ParentNo from [Port_D ...
- SQL实现递归及存储过程中In()参数传递解决方案[转]
SQL实现递归及存储过程中In()参数传递解决方案 1.SQL递归 在SQL Server中,我们可以利用表表达式来实现递归算法,一般用于阻止机构的加载及相关性处理. -->实现: 假设 ...
- SQL实现递归及存储过程中 In() 参数传递解决方案
1.SQL递归 在SQL Server中,我们可以利用表表达式来实现递归算法,一般用于阻止机构的加载及相关性处理. -->实现: 假设OrganiseUnit(组织机构表)中主要的三个字段为Or ...
- SQL With (递归CTE查询)
指定临时命名的结果集,这些结果集称为公用表表达式 (CTE).该表达式源自简单查询,并且在单条 SELECT.INSERT.UPDATE 或 DELETE 语句的执行范围内定义.该子句也可用在 CRE ...
- SQL Server 递归
SQL Server 没有类似于Oracle START WITH NAME='xx' CONNECT BY PRIOR ID=PARENT_ID这样的语句,但是可以通过自定义标准函数+With语句实 ...
- 求SQL语句递归的算法
表结构是这样的 部门 上级部门 A BB CC DA AB BC C ...
- sql server递归日期
在做项目任务时,需要将一个日期范围转换为日期表. 例如:日期范围(2017年01月21日~2017年02月20日).转换成一日为单位的日期表,如下. 2017-01-21 2017-01-22 201 ...
- sql server 递归汇总 按指定层级汇总
每个地区递归层级可能不一致,数据表(table)存放最小层级地区 area --地区层级表 id name f_id leve 1 中国 0 1 2 湖北 1 2 3 武汉 2 3 ... --测试数 ...
- SqlServer里,一条sql进行递归删除
Server 2005中提供了公用表表达式(CTE),使用CTE,可以使SQL语句的可维护性,同时,CTE要比表变量的效率高得多. 存储过程方法: create proc up_delete_ncla ...
- sql with 递归 查询特定区间日期
declare @startDay smalldatetime ='2013-01-01' ;with cte as( select @startDay as d union all ...
随机推荐
- Angular 2 从0到1 (三)
作者:王芃 wpcfan@gmail.com 第一节:Angular 2.0 从0到1 (一)第二节:Angular 2.0 从0到1 (二)第三节:Angular 2.0 从0到1 (三)第四节:A ...
- Rust 学习 0
安装Rust 后,本地有文档: file:///usr/local/share/doc/rust/html/index.html file:///usr/local/share/doc/rust/ht ...
- 也说border-box盒模型
border-box是css3的一个新属性,使用这个属性,和以往的content-box比起来,会有诸多便利之处,bootstrap3也使用的是这个border-box,甚至很多人认为,border- ...
- Nginx - Additional Modules, Website Access and Logging
The following set of modules allows you to configure how visitors access your website and the way yo ...
- HDOJ2021发工资咯:)
发工资咯:) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- 如何将 select top 4 id from table1 赋值 给 declare @id1 int,@id2 int,@id3 int,@id4 int
declare @id1 int,@id2 int,@id3 int,@id4 int ),) select @sickcode = sickcode,@sfrq =sfrq from tablena ...
- StrictMode模式介绍
最新的Android平台中(Android 2.3起),新增加了一个新的类,叫StrictMode(android.os.StrictMode).这个类可以用来帮助开发者改进他们编写的应用,并且提供了 ...
- Sublime Text 3下 Emmet 使用小技巧
Emmet常用技巧:(输入下面简写,按Tab键可触发效果) 生成 HTML 文档初始结构 html:5 或者 ! 生成 HTML5 结构 ...
- CentOS 7 下使用 Firewall
在 CentOS 7 中,引入了一个新的服务,Firewalld,下面一张图,让大家明确的了解 Firewall 与 iptables 之间的关系与区别. 安装它,只需 yum install fir ...
- OC4_内存管理法则
// // Dog.h // OC4_内存管理法则 // // Created by zhangxueming on 15/6/18. // Copyright (c) 2015年 zhangxuem ...