树型结构查询语句备忘

SELECT TOP 1000 [ID]
      ,[ParentID]
      ,[Name]
      ,[Content]
      ,HasChildren = ISNULL((SELECT 1  WHERE EXISTS(SELECT TOP 1 1 FROM t_Tree WHERE ParentID = A.ID)),0)
FROM [Test].[dbo].[t_Tree] A

 

posted on 2014-08-26 13:15  空明流光  阅读(151)  评论(0编辑  收藏  举报

导航