zoukankan      html  css  js  c++  java
  • SQL递归查询子类型

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[F_GetChildCate]'and xtype in (N'FN', N'IF', N'TF'))
    drop function [dbo].[F_GetChildCate]
    GO

    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS OFF 
    GO

    Create Function F_GetChildCate(@Id int
    Returns  @Child Table([CateId] int,CateName nvarchar(127),ParentId int)
    As 
    Begin 

        
    Begin            
             
    Insert @Child Select Id,C_CateName,C_ParentID  From [T_Cate] Where [C_ParentID] = @Id
            
    While @@ROWCOUNT > 0
                    
    Begin                     
                
    Insert @Child Select B.Id,B.C_CateName,B.C_ParentID  From @Child A 
                
    Inner Join [T_Cate] B On A.[CateId]=B.[C_ParentID] 
                
    Where B.[C_ParentID] Not In (Select Distinct [ParentId] From @Child
                    
    End 
            
    End
       
        
    Return 
    End

    GO
    SET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO

  • 相关阅读:
    反射
    IDEA配置数据库
    配置idea的maven镜像为aliyun
    蓝桥---芯片测试(思维)
    汉诺塔(思维、DP思想)
    立方数(质因子、优化)
    碎碎念(DP)
    牛牛战队的比赛地(三分)
    子段乘积(尺取、逆元)
    子段异或(位运算)
  • 原文地址:https://www.cnblogs.com/skyblue/p/1249621.html
Copyright © 2011-2022 走看看