打印本文 打印本文 关闭窗口 关闭窗口
整理了一些t-sql技巧
作者:武汉SEO闵涛  文章来源:敏韬网  点击数16761  更新时间:2007/11/14 13:12:55  文章录入:mintao  责任编辑:mintao
go

--查询指定id的所有子
create function f_cid(
@id int
)
returns @re table([id] int,[level] int)
as
begin
 
declare @l int
 
set @l=0
 
insert @re select @id,@l
 
while @@rowcount>0
 
begin
  
set @l=@l+1
  
insert @re select a.[id],@l
  
from [tb] a,@re b
  
where a.[pid]=b.[id] and b.[level]=@l-1
 
end
/**//*--如果只显示最明细的子(下面没有子),则加上这个删除
 delete a from @re a
 where exists(

 << 上一页  [11] [12] [13] [14] [15] [16] [17] [18] [19]  下一页

打印本文 打印本文 关闭窗口 关闭窗口