为了账号安全,请及时绑定邮箱和手机立即绑定

请教SQL关于游标的问题

请教SQL关于游标的问题

汪汪一只猫 2018-12-06 23:04:53
存储过程有个参数,根据这个参数来分别写的游标查询语句,但是处理这个游标是同一个代码,好像不能同时定义两次,我又不想把后续的处理代码写两次,有什么办法吗? declare @tempid int,@lasttime datetime,@sql nvarchar(1000) set @tempid=0; BEGIN SET NOCOUNT ON; if @para1='oneself' begin declare bzrid cursor for select id from erpzjbzrlist as a end else if @para1='all' begin declare bzrid cursor for select id from erpzjbzrlist as a where (select max(endtime) from erpzjphasetime where bianhao=a.id group by bianhao) >=getdate(); end else begin return -1 end open bzrid fetch next from bzrid into @tempid while (@@fetch_status=0) begin select @lasttime =max(endtime) from erpzjphasetime where bianhao=(select id from erpzjbzrlist as a where (select max(endtime) from erpzjphasetime where bianhao=a.id group by bianhao) >=getdate() and id<@tempid) group by bianhao if(@lasttime<>null) begin select @lasttime=dateadd(day,1,@lasttime); exec ERP_p_adjustProjectTime @tempid,@lasttime; end fetch next from bzrid into @tempid end
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 553 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信