你这个问题是有点复杂。
你可以先 声明一个本地变量。再把光标的值赋给它。就可以搞定。
我想了好久都不明白为什么会这样。我开始执行时发现该procedure有很多recordset。所以delphi会报错。后来才发现光标的值没有赋给一个本地变量才会导致多recordset的情况。我查了online help 也没能找的why?
希望大家继续找出why?
CREATE proc RefreshNo(@aFldName char(40),@aTabName char(40)) AS
execute('declare cur1 cursor for select '+@aFldName+' from '+@aTabName)
declare @i int
declare @ci char(4) ,@k char(40)
select @i=1
select @ci=convert(char,@i)
open cur1
fetch next from cur1 into @k
while @@fetch_status=0
begin
select @ci=convert(char,@i) ----语句1
execute('update '+@aTabName+' set '+@aFldName+'='+@ci+' where current of cur1') ----语句2
select @i=@i+1
fetch next from cur1 into @k
end
close cur1
deallocate cur1
你可以先 声明一个本地变量。再把光标的值赋给它。就可以搞定。
我想了好久都不明白为什么会这样。我开始执行时发现该procedure有很多recordset。所以delphi会报错。后来才发现光标的值没有赋给一个本地变量才会导致多recordset的情况。我查了online help 也没能找的why?
希望大家继续找出why?
CREATE proc RefreshNo(@aFldName char(40),@aTabName char(40)) AS
execute('declare cur1 cursor for select '+@aFldName+' from '+@aTabName)
declare @i int
declare @ci char(4) ,@k char(40)
select @i=1
select @ci=convert(char,@i)
open cur1
fetch next from cur1 into @k
while @@fetch_status=0
begin
select @ci=convert(char,@i) ----语句1
execute('update '+@aTabName+' set '+@aFldName+'='+@ci+' where current of cur1') ----语句2
select @i=@i+1
fetch next from cur1 into @k
end
close cur1
deallocate cur1
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货