zoukankan      html  css  js  c++  java
  • 尝试sql2005的新特性,递归查询

    --尝试sql2005的新特性,递归
    --取得所有子信息


    ------------------------------------
    --用途: 创建功能表
    --项目名称:
    --创建人: 王召冠
    --说明: 
    --时间: 
    ------------------------------------
    CREATE TABLE tFunction
    (
     OID   bigint primary key identity(1, 1),
     vName  nvarchar(50) not null,
     vLabel  nvarchar(50),
     lParent  bigint,
     iDispOrder int,
     vImageUrl nvarchar(50),
     vRemark  nvarchar(500),
     iVersion int
    )
    GO

    -- 停止自动增长键
    SET IDENTITY_INSERT [tFunction] ON
    GO

    INSERT INTO tFunction(OID, vName, vLabel, iDispOrder, vImageUrl, lParent, vRemark)  select  1, '系统设置', '系统设置', 8, '', null, ''
    INSERT INTO tFunction(OID, vName, vLabel, iDispOrder, vImageUrl, lParent, vRemark)  select  2, '用户管理', '用户管理', 6, '', null, ''
    INSERT INTO tFunction(OID, vName, vLabel, iDispOrder, vImageUrl, lParent, vRemark)  select  3, '功能设置', '功能设置', 6, '', 1, ''
    INSERT INTO tFunction(OID, vName, vLabel, iDispOrder, vImageUrl, lParent, vRemark)  select  4, '用户管理', '用户管理', 2, '', 2, ''
    GO

    -- 启动自动增长
    SET IDENTITY_INSERT [tFunction] OFF
    GO


    -- 递归查询
    WITH abc
    AS
    (
     SELECT *, 0 AS iLevel
     FROM [tFunction] AS t
     WHERE t.[OID] = 1
     UNION ALL
     SELECT t.*, [abc].iLevel + 1 AS iLevel
     FROM [tFunction] AS t
      JOIN [abc] ON t.[lParent] = [abc].OID
    )

    SELECT *
    FROM [abc]



  • 相关阅读:
    Vue中改变对象的注意事项
    Object.assign简单总结
    Base64编码
    vue中prop传值时加不加v-bind(冒号:)
    内联元素的padding和margin
    flex自适应宽度显示省略号
    Http和Https
    JVisualVM 模拟一次内存泄漏场景分析
    Lucene
    布隆算法原理
  • 原文地址:https://www.cnblogs.com/zhaoguan_wang/p/1176195.html
Copyright © 2011-2022 走看看