create function fnGetFather(@id nvarchar(30))
returns @t table(zth nvarchar(30),fth nvarchar(30))as
begin
select @id = fth from gx where zth = @id
while @@rowcount > 0
begin
insert into @t select zth,fth from gx where zth = @id
select @id = fth from gx where zth = @id
end
return
end
GO
select * from dbo.fnGetFather('1') order by 1 DESC
通过执行函数,我想要这样的结果
(5、8)
(5、9)
(6、10)
(7、11)
但每次执行函数,返回的值都不一样,有如下规律。
执行第一次
(5、8)
(5、9)
执行第二次
(6、10)
执行第三次(7、11)
请大家帮忙改改以上函数,多谢了!! qq: 636297788

1万+

被折叠的 条评论
为什么被折叠?



