CREATE procedure gridview (@fathername nvarchar(50))
as
declare @t table(n_name nvarchar(50),n_father nvarchar(50),level int,Sort nvarchar(4000))
declare @i int
set @i=1
insert into @t select n_name,n_fathername,@i,n_name from news where n_fathername=@fathername
while @@Rowcount>0
begin
set @i=@i+1
insert into @t
select a.n_name,a.n_fathername,@i,b.Sort+a.n_name from news a left join @t b on a.n_fathername=b.n_name where
b.level=@i-1
end
select a.n_id,REPLICATE('-',b.level*2-2)+'├'+a.n_name,a.n_class,a.n_type,a.n_shunxu from news a left join @t b on
a.n_name=b.n_name order by b.Sort
GO