存儲過程中帶遊標

Create Procedure UpdateTimeProperty
@SurroundingRock  nvarchar(200),
@IFClassName  nvarchar(200),
@Prop_StartStation nvarchar(200),
@Prop_EndStatoin nvarchar(200),
@StartTime nvarchar(200),
@UnitTime nvarchar(200)
as
begin
declare @curStartStation nvarchar(200)
declare @curEndStatoin nvarchar(200)
declare @EBS nvarchar(200)
declare getNum cursor
for(select Prop_StartStation,Prop_EndStatoin,EBS from v_ItemProperty
where SurroundingRock=@SurroundingRock and  IfcClassName=@IFClassName)
open getNum;
fetch next from getNum into @curStartStation,@curEndStatoin,@EBS;
while @@FETCH_STATUS = 0
    begin
	  if(
	    ((select dbo.f_GetNum(@curStartStation) as curStartStation) > (select dbo.f_GetNum(@Prop_StartStation) as Prop_StartStation)) and  -----遊標中的開始樁號大於參數的開始樁號
		((select dbo.f_GetNum(@curEndStatoin) as curEndStatoin)<(select dbo.f_GetNum(@Prop_EndStatoin) as Prop_EndStatoin) )  and-----遊標中的結束樁號要小於參數的結束樁號
	     ((select dbo.f_GetNum(@curStartStation) as curStartStation) <(select dbo.f_GetNum(@Prop_EndStatoin) as Prop_EndStatoin))and-----遊標中的開始樁號小於參數的結束樁號
		 ((select dbo.f_GetNum(@curEndStatoin) as curEndStatoin)>(select dbo.f_GetNum(@Prop_StartStation) as Prop_StartStation))    -------遊標中的結束樁號大於參數中的開始樁號
	   )
	   update t_ComponentProperty
	   set Value=@curStartStation
	   where t_ComponentProperty.EBS=@EBS and Name='ScheduleStartTime';
	   update t_ComponentProperty
	   set Value=@curEndStatoin
	   where t_ComponentProperty.EBS=@EBS and Name='ScheduleEndTime';
	fetch next from getNum into @curStartStation,@curEndStatoin,@EBS;
	end
	close getNum
	deallocate getNum
	end
go

發佈了32 篇原創文章 · 獲贊 9 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章