这是我的自定义的一个方法
create function aa(@upperid int)
returns @t table (id int,upperid int,level int)
as
begin
declare @i int
set @i=1
insert into @t
select *,@i from t where upperid=@upperid
while @@rowcount>0
begin
set @i=@i+1
insert into @t
select a.*,@i from t a left join @t b on a.upperid=b.id
where b.level=@i-1
end
return
end我创建的一个简单的表
SQL> select * from t;
 
                                     ID                                 UPPERID
--------------------------------------- ---------------------------------------
                                      1                                       2
                                      3                                       2
                                      4                                       1
                                      5                                       3最后我执行 select * from budgettest.aa(1) 就报错  就指教