加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sqlserver实现oracle递归树函数例子(start with.....connect by

发布时间:2020-12-12 15:27:32 所属栏目:MsSql教程 来源:网络整理
导读:?sqlserver实现oracle递归函数的例子(start with.....connect by prior.....) 通过将查询遍历到的数据插入临时表方式实现 此函数应该在考虑下这个临时表的删除文件 以及创建时再判断表结构是否已经存在,相信这个应该很容易........ 使用方法 select * from
?sqlserver实现oracle递归函数的例子(start with.....connect by prior.....) 通过将查询遍历到的数据插入临时表方式实现 此函数应该在考虑下这个临时表的删除文件 以及创建时再判断表结构是否已经存在,相信这个应该很容易........ 使用方法
select * from dbo.getSubCompany(24) ? 返回结果集结构 taxi_company_id int,taxi_company_name varchar(200),super_company_id int,level int ? ? 目前不支持动态表名和列名 ? 函数定义 create function getSubCompany(@idPart int)
returns?? @tabinfo table(taxi_company_id int,level int)
as
begin ? declare @cid int
set @cid = 1 ? ??? insert @tabinfo
??? select taxi_company_id,taxi_company_name,super_company_id,@cid from taxi_company where taxi_company_id = @idPart ? ??? while @@rowcount>0
??? begin ? ????? set @cid = @cid + 1 ? ????? insert @tabinfo
????? select distinct x.taxi_company_id,x.taxi_company_name,x.super_company_id,@cid
????? from taxi_company as x join? @tabinfo as y
????? on x.super_company_id=y.taxi_company_id
????? where y.level = @cid-1
??? end
?? return ? end

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读