首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

存储过程递归调用 拜请高手指教,该如何处理

2012-01-08 
存储过程递归调用 拜请高手指教alterprocedureniubin_IsAccountHasChild---判断是否有字节点(@FAccountIDi

存储过程递归调用 拜请高手指教
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

[解决办法]

热点排行
Bad Request.