zoukankan      html  css  js  c++  java
  • SQL Server 树查询

    WITH tree
    AS
    (
    SELECT ParentAssetID, AssetID,1 AS x2level,nodename,
    CAST(nodename AS NVARCHAR(max)) x2name,
    CAST(+AssetID AS NVARCHAR(max)) x2id
    FROM dbo.Assets
    WHERE ParentAssetID IS null
    UNION ALL
    SELECT c.ParentAssetID, c.AssetID, tree.x2level + 1,c.nodename, 
    CAST(REPLICATE('-', x2level * 4) + c.nodename AS NVARCHAR(max)) x2name,
    tree.x2id +':|:'+ CAST(c.AssetID AS NVARCHAR(max)) x2id
    FROM dbo.Assets c
    INNER JOIN tree
    ON c.ParentAssetID = tree.AssetID
    )
    SELECT x2name, AssetID, ParentAssetID FROM tree
    ORDER BY x2id;

    ---President
    ------Vice President
    ---------CEO
    ---------CTO
    ------------Group Project Manager
    ---------------Project Manager 1
    ------------------Team Leader 1
    ---------------------Software Engineer 1
    ---------------------Software Engineer 2
    ------------------Test Lead 1
    ---------------------Tester 1
    ---------------------Tester 2
    ---------------Project Manager 2
    ------------------Team Leader 2
    ---------------------Software Engineer 3
    ---------------------Software Engineer 4
    ------------------Test Lead 2
    ---------------------Tester 3
    ---------------------Tester 4
    ---------------------Tester 5
     
  • 相关阅读:
    [基础]编程环境配置
    MonoDevelop line endings
    Unity手机平台播放影片
    [3D跑酷] GUIManager UI管理
    [3D跑酷] UI事件处理系统
    [3D跑酷] AudioManager
    NGUI学习笔记汇总
    Unity3D开发之搭建Mac OS开发环境
    Unity键值(KeyCode)
    Unity3D多人协作开发环境搭建
  • 原文地址:https://www.cnblogs.com/mingjing/p/6041523.html
Copyright © 2011-2022 走看看