MSSQL查找指定節點下的子結點
来源:互联网 发布:数据挖掘环节包括 编辑:程序博客网 时间:2024/06/01 18:36
-->Title:Generating test data
-->Author:wufeng4552
-->Date :2012-09-30 08:52:38
set nocount on
if object_id('tb','U')is not null drop table tb
go
create table tb(ID int, ParentID int)
insert into tb select 1,0
insert into tb select 2,1
insert into tb select 3,1
insert into tb select 4,2
insert into tb select 5,3
insert into tb select 6,5
insert into tb select 7,6
-->Title:查找指定節點下的子結點 来自: http://www.52mvc.com
if object_id('Uf_GetChildID')is not null drop function Uf_GetChildID
go
create function Uf_GetChildID(@ParentID int)
returns @t table(ID int)
as
begin
insert @t select ID from tb where ParentID=@ParentID
while @@rowcount<>0
begin
insert @t select a.ID from tb a inner join @t b
on a.ParentID=b.id and
not exists(select 1 from @t where id=a.id)
end
return
end
go
select * from dbo.Uf_GetChildID(5)
/*
ID
-----------
6
7
*/
-->Title:查找指定節點的所有父結點
if object_id('Uf_GetParentID')is not null drop function Uf_GetParentID
go
create function Uf_GetParentID(@ID int)
returns @t table(ParentID int)
as
begin
insert @t select ParentID from tb where ID=@ID
while @@rowcount!=0
begin
insert @t select a.ParentID from tb a inner join @t b
on a.id=b.ParentID and
not exists(select 1 from @t where ParentID=a.ParentID)
end
return
end
go
select * from dbo.Uf_GetParentID(2)
/*
ParentID
-----------
1
0
*/
-->Author:wufeng4552
-->Date :2012-09-30 08:52:38
set nocount on
if object_id('tb','U')is not null drop table tb
go
create table tb(ID int, ParentID int)
insert into tb select 1,0
insert into tb select 2,1
insert into tb select 3,1
insert into tb select 4,2
insert into tb select 5,3
insert into tb select 6,5
insert into tb select 7,6
-->Title:查找指定節點下的子結點 来自: http://www.52mvc.com
if object_id('Uf_GetChildID')is not null drop function Uf_GetChildID
go
create function Uf_GetChildID(@ParentID int)
returns @t table(ID int)
as
begin
insert @t select ID from tb where ParentID=@ParentID
while @@rowcount<>0
begin
insert @t select a.ID from tb a inner join @t b
on a.ParentID=b.id and
not exists(select 1 from @t where id=a.id)
end
return
end
go
select * from dbo.Uf_GetChildID(5)
/*
ID
-----------
6
7
*/
-->Title:查找指定節點的所有父結點
if object_id('Uf_GetParentID')is not null drop function Uf_GetParentID
go
create function Uf_GetParentID(@ID int)
returns @t table(ParentID int)
as
begin
insert @t select ParentID from tb where ID=@ID
while @@rowcount!=0
begin
insert @t select a.ParentID from tb a inner join @t b
on a.id=b.ParentID and
not exists(select 1 from @t where ParentID=a.ParentID)
end
return
end
go
select * from dbo.Uf_GetParentID(2)
/*
ParentID
-----------
1
0
*/
- MSSQL查找指定節點下的子結點
- 查找指定文件夹下的指定格式文件
- 查找指定类型的驱动器
- 查找指定类型的驱动器
- [MSSQL]获取指定索引的值的函数
- MsSQL 获得指定表的所有(数据插入脚本)
- MsSql获得指定表的 表结构脚本
- MSSQL 查找子結節與父節點
- [MSSQL]查找最新报价----谈group by的简单用法
- MSSQL查找数据所在的表与列
- [MSSQL]向左填充指定字符串
- 在指定路径或者是文件名查找指定的字符串
- 在指定路径或者是文件名查找指定的字符串
- delphi 查找指定目录,指定扩展名的所有文件名
- 在指定路径或者是文件名查找指定的字符串
- 指定目录中批量查找指定后缀名的文件(Python)
- Linux中查找指定大小或者指定内容的文件
- vc查找指定目录下的文件:
- C++ Builder中
- 实现页面某元素位置固定
- FLASH AS STUDY
- 大写字母转换小写
- hello world入门程序(发送邮件)二
- MSSQL查找指定節點下的子結點
- 关于Boolean, Number, String
- Windows Azure Platform体验(1):Windows Azure
- 【计算机网络】计算机网络面试题 系列二
- Drools Guvnor(jbpm5学习资料)
- MSSQL处理表重复记录
- 脚本参数的使用(ex17.sh)
- ContentProvider和Uri详解
- 等概率产生0和1(延伸)