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 ...
随机推荐
- 转:艾瑞咨询2016 IM云的发展趋势
转自: http://www.cnblogs.com/lingyunhu/p/rtc63.html
- Linux时间函数
一.时间编程 1.核心理论 (1).时间类型 2.函数学习 (1).获取日历时间 函数名:time 函数原型:time_t time(time_t *t) 函数功能:获取当前日历时间 所属头文件:&l ...
- jQuery点击图片弹出大图遮罩层
使用jQuery插件HoverTreeShow弹出遮罩层显示大图 效果体验:http://hovertree.com/texiao/hovertreeshow/ 在开发HoverTreeTop项目的产 ...
- select选项框特效
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- Ehcache(2.9.x) - API Developer Guide, Cache Exception Handlers
About Exception Handlers By default, most cache operations will propagate a runtime CacheException o ...
- 编译mosquitto出现的问题
[root@localhost mosquitto-1.3]# make WITH_TLS=no set -e; for d in lib client src; do make -C ${d}; d ...
- kafka集群安装与配置
一.集群安装 1. Kafka下载: 可以从kafka官方网站(http://kafka.apache.org)上找到下载地址,再wgetwget http://mirrors.cnnic.cn/ap ...
- Annotation注解与butterknife
注解分为三种,一般来讲我们使用的是运行时会加载及能够反射读取的注解类型, 其他编译器生效的类型和编译后放入类文件而运行期不能加载解析的对我们没啥用. 所以从普通理解上来看,注解要配合着反射用就好了. ...
- Unity 5.4大赞:HTC Vive经典The lab渲染器开源
HTC Vive提供了一个不错的免费VR demo,最近1周仔细体验了一番. 仔细看了其安装文件,竟然是Unity 5.4beta版本(通过查log,知道Valve公司用的是最新的5.4.0b11版本 ...
- jQuery实现CheckBox全选、全不选
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...