B
Beast
Unregistered / Unconfirmed
GUEST, unregistred user!
有一数据表,存放一数状结构
Table jl_Unit
uId int //结点ID
uParentUnitId int //父结点ID
uPower int //结点Power值
我欲实现一个存储过程(以下简称SP), 类似于Set_Power @id,@power
来实现变更某一结点的upower值,并同时变更其子结点的uPower值.
我做了一个SP如下:
Create Procedure [dbo].[sp_SetPower]
@Id int,
@power int
AS
declare
@n_Id int
update jl_Unit set uPower=@power where uId=@Id
declare
my_cursor cursor for select uId from jl_Unit where uParentUnitId=@Id
open my_cursor
fetch next from my_cursor into @n_Id
while @@FETCH_STATUS = 0
begin
Exec sp_SetPower @Id,@power
fetch next from my_cursor into @n_Id
end
close my_cursor
DeAllocate my_cursor
但是我发现递归调用自己的时候my_cursor不是象Delphi的局部变量,而是全局的.
该怎么办呢?
Table jl_Unit
uId int //结点ID
uParentUnitId int //父结点ID
uPower int //结点Power值
我欲实现一个存储过程(以下简称SP), 类似于Set_Power @id,@power
来实现变更某一结点的upower值,并同时变更其子结点的uPower值.
我做了一个SP如下:
Create Procedure [dbo].[sp_SetPower]
@Id int,
@power int
AS
declare
@n_Id int
update jl_Unit set uPower=@power where uId=@Id
declare
my_cursor cursor for select uId from jl_Unit where uParentUnitId=@Id
open my_cursor
fetch next from my_cursor into @n_Id
while @@FETCH_STATUS = 0
begin
Exec sp_SetPower @Id,@power
fetch next from my_cursor into @n_Id
end
close my_cursor
DeAllocate my_cursor
但是我发现递归调用自己的时候my_cursor不是象Delphi的局部变量,而是全局的.
该怎么办呢?