存储过程有个参数,根据这个参数来分别写的游标查询语句,但是处理这个游标是同一个代码,好像不能同时定义两次,我又不想把后续的处理代码写两次,有什么办法吗?
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
相关分类