存储过程递归调用 拜请高手指教
alter procedure niubin_IsAccountHasChild --- 判断是否有 字节点
(
@FAccountID integer,
@FRootID integer
)
as
Select * from t_Account where FParentID =@FAccountID and FRootID = @FRootID
if @@RowCount > 0
return 1
else
return 0
go
Alter procedure niubin_GetChild
(@FRootID int,
@FAccountID int
)
as
declare MyCursor cursor scroll for
Select FAccountID from t_Account where FParentID =@FAccountID and FRootID = @FRootID
open MyCursor
declare @FAccountIDTemp sysname
declare @IsHasChild int
fetch next from MyCursor into @FAccountIDTemp
while(@@fetch_status=0)
begin
Exec @IsHasChild = niubin_IsAccountHasChild @FAccountIDTemp, 1004--- 判断是否有 字节点 这里也不知道对不
if @IsHasChild = 1
Exec niubin_GetChild 1004, @FAccountIDTemp ---如果有字节点 继续判断字节点(在此调用存储过程本身不知道对不)
else
print @FAccountIDTemp ---如果没有则打印 出该字节点
fetch next from MyCursor into @FAccountIDTemp
end
close MyCursor
deallocate MyCursor
Exec niubin_GetChild 1004, 1007
------解决方案--------------------顶