sqlserver查询树表某个节点所有的子节点

DECLARE
    @s VARCHAR (MAX) SELECT
        @s = ',' + CAST (kindid AS VARCHAR(20)) + ''
    FROM
        treetable
    WHERE
        kindid = '25'
    WHILE @@ROWCOUNT > 0 SELECT
        @s =@s + ',' + CAST (kindid AS VARCHAR)
    FROM
        treetable
    WHERE
        charindex(
            ',' + CAST (kindid AS VARCHAR) + ',' ,@s + ','
        ) = 0
    AND charindex(
        ',' + CAST (parentkindid AS VARCHAR) + ',' ,@s + ','
    ) > 0 SELECT
        kindid,
        kindname,
        parentkindid
    FROM
        treetable
    WHERE
        charindex(
            ',' + CAST (kindid AS VARCHAR) + ',' ,@s + ','
        ) > 0
   


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010060662/article/details/51544990
文章标签: sql sqlserver
个人分类: sqlserver sql
上一篇sqlserver清除小数点后无效的0位
下一篇response.setContentType(MIME)
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭