存儲過程有個參數,根據這個參數來分別寫的游標查詢語句,但是處理這個游標是同一個代碼,好像不能同時定義兩次,我又不想把后續的處理代碼寫兩次,有什么辦法嗎?
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
請教SQL關于游標的問題
汪汪一只貓
2018-12-06 23:04:53