请帮忙看看这个游标处理,是否存在问题。
declare @s varchar(4000),@gs int,@jb int,@j_int int
--定义游标
set @s='declare mycursor cursor for
select 补时,补加班,工时电脑工号 from '+ @FILENAMEGS + ' WHERE (工时电脑工号 in(select 工时电脑工号 from temp_selfind)
AND (工时日期 like '+ @s_date +'))'
exec(@s)
open mycursor -- 打开游标
fetch next from mycursor into @gs,@jb,@j_int
while @@fetch_status=0
begin
If @Weekday = 0
begin
exec('
update '+ @FILENAMEGSY +' set 月补时 = 月补时 -'+ @gs +',
月补加班= 月补加班 -'+ @jb +',
月休假时间 = 月休假时间 -'+ @gs +'-'+ @jb +'
where (月工时电脑工号 ='+ @j_int +')
AND (月工时日期 like left('+ @s_date +',6))
update '+ @FILENAMEGSY +' set 月补时 = 月补时 + '+ @s_all +',
月补加班= 月补加班 + '+ @s_addh +',
月休假时间 = 月休假时间 +'+ @s_addh +'+ '+ @s_all +'
where (月工时电脑工号 ='+ @j_int +')
AND (月工时日期 like left('+ @s_date +',6))
update '+ @FILENAMEGS +' set 补时 = '+ @s_all +',补加班= '+ @s_addh +'
where (工时电脑工号 ='+ @j_int +') AND (工时日期 like '+ @s_date +')')
end
Else
begin
exec('update '+ @FILENAMEGS +' set 补时 = '+ @s_all +',补加班='+ @s_addh +'
where (工时电脑工号 ='+ @j_int +') AND (工时日期 like '+ @s_date +')
update '+ @FILENAMEGSY +'
set 月补时 = 月补时 - '+ @gs +'+ '+ @s_all +',
月补加班= 月补加班 - '+ @jb +'+'+ @s_addh +'
where (月工时电脑工号 ='+ @j_int +') AND
(月工时日期 like left('+ @s_date +',6)) ')
end
end
Fetch next from mycursor Into @gs,@jb,@j_int --没有继续读取下一条
close mycursor
deallocate mycursor
---------处理这个游标会不会失败呢?没运行时数据是更新了,但好象没退出来。