zoukankan      html  css  js  c++  java
  • sql 根据父节点查找所有子节点

     set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go


    ALTER   function   f_id(@parentid  int)  
      returns   @re   table(orderid   int,parentid   int,title   nvarchar(50),level   int)  
      as  
      begin  
      declare   @l   int  
      set   @l=0  
      insert @re select @parentid,null,'',-1
      insert   @re   select   TabID,   ParentTabID   ,TabName,@l   from   rb_Tabs  
      where   ParentTabID=@parentid   
      while   @@rowcount>0  
      begin  
      set   @l=@l+1  
                      insert   into   @re   select    
                      a.TabID,a.ParentTabID,a.TabName,@l  
                      from   rb_Tabs   a,@re   b  
                      where   a.ParentTabID=b.orderid   and   b.level=@l-1   
      end  
      return  
      end  
      go  
    --------------------------------------------------------------
    使用方法

    declare @cat int
    set @cat  = 406
    SELECT
           rb_Products_st.ProductID,
       rb_Products_st.DisplayOrder,
       rb_Products_st.ModelNumber,
       rb_Products_st.ModelName,
       rb_Products_st.UnitPrice,
       rb_Products_st.FeaturedItem,
       rb_Products_st.LongDescription,
       rb_Products_st.ShortDescription,
       rb_Products_st.MetadataXml,
       rb_Products_st.Weight,
       rb_Products_st.TaxRate
      FROM
       rb_Products_st
      WHERE
          rb_Products_st.CategoryID in (select   orderid   from   dbo.f_id(@cat) )

  • 相关阅读:
    C#编程总结 字符转码
    获取 苹果UDID 序列号
    SVN :This XML file does not appear to have any style information associated with it.
    oracle 实时查询最耗CPU资源的SQL语句
    Oracle 优化和性能调整
    weblogic管理脚本
    weblogic状态监控脚本
    oracle性能检测sql语句
    Oracle动态性能表-V$SESSION_WAIT,V$SESSION_EVENT
    linux HBA 卡驱动安装
  • 原文地址:https://www.cnblogs.com/netwom/p/950319.html
Copyright © 2011-2022 走看看