惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Forbes - Security
Forbes - Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
F
Fortinet All Blogs
B
Blog
T
The Blog of Author Tim Ferriss
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
Y
Y Combinator Blog
Microsoft Azure Blog
Microsoft Azure Blog
L
LangChain Blog
Recent Announcements
Recent Announcements
U
Unit 42
Martin Fowler
Martin Fowler
M
MIT News - Artificial intelligence
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
The Register - Security
The Register - Security
Recorded Future
Recorded Future
C
Check Point Blog
V
V2EX
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
酷 壳 – CoolShell
酷 壳 – CoolShell
F
Full Disclosure
小众软件
小众软件
A
About on SuperTechFans
云风的 BLOG
云风的 BLOG
宝玉的分享
宝玉的分享
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
爱范儿
爱范儿
P
Proofpoint News Feed
罗磊的独立博客
量子位
D
Docker
博客园_首页
D
DataBreaches.Net
Project Zero
Project Zero
博客园 - 司徒正美
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - Franky
Security Latest
Security Latest
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
N
Netflix TechBlog - Medium
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
大猫的无限游戏
大猫的无限游戏

博客园 - 徘徊中的海鸟

在Dictionary使用foreach的注意 ADO.NET,连接\连接池问题 - 徘徊中的海鸟 - 博客园 关于sql server占用系统资源的问题 ASP.NET 的内存不足问题 SQL拆分字段 生成代码自动加入到解决方案中 SQL Server 2005数据库日志文件损坏的情况下如何恢复数据库 .net 发现的cache 问题 .NET线程若干问题 HttpContext.Cache 和 HttpRuntime.Cache IIS 6.0中配置HTTP Gzip压缩 pre标签自动换行方案 HttpWebRequest 和 浏览器打开的区别 TestDirector 安装、使用心得 连接数问题 w3wp 进程问题 关于CultureInfo 提高sql的效率 SQL中只获取日期值
读取树数据SQL
徘徊中的海鸟 · 2007-05-11 · via 博客园 - 徘徊中的海鸟

 --生成测试数据  
  create   table   BOM(ID   INT,PID   INT,MSG   VARCHAR(1000))  
  insert   into   BOM   select   1,0,NULL  
  insert   into   BOM   select   2,1,NULL  
  insert   into   BOM   select   3,1,NULL  
  insert   into   BOM   select   4,2,NULL  
  insert   into   BOM   select   5,3,NULL  
  insert   into   BOM   select   6,5,NULL  
  insert   into   BOM   select   7,6,NULL  
  go  
   
  --创建用户定义函数  
  create   function   f_getChild(@ID   VARCHAR(10))  
  returns   @t   table(ID   VARCHAR(10),PID   VARCHAR(10),Level   INT)  
  as  
  begin  
          declare   @i   int,@ret   varchar(8000)  
          set   @i   =   1  
          insert   into   @t   select   ID,PID,@i   from   BOM   where   PID   =   @ID  
           
          while   @@rowcount<>0  
          begin  
                  set   @i   =   @i   +   1  
                   
                  insert   into   @t    
                  select    
                          a.ID,a.PID,@i    
                  from    
                          BOM   a,@t   b    
                  where    
                          a.PID=b.ID   and   b.Level   =   @i-1  
          end  
          return  
  end  
  go  
   
  --执行查询  
  select   *   from   dbo.f_getChild(0)  
  go  
   
  --输出结果  
  /*  
  5  
  6  
  7  
  */  
   
  --删除测试数据  
  drop   function   f_getChild  
  drop   table   BOM

posted on 2007-05-11 17:33  徘徊中的海鸟  阅读(251)  评论()    收藏  举报