读书人

SQL Server 结果集循环处置的 避免游标

发布时间: 2013-04-05 10:24:33 作者: rapoo

SQL Server 结果集循环处理的 避免游标处理方法

declare @tempTable table(ID int identity(1,1), unitID int, unitState int, partID bigint)insert into @tempTableselect distinct u.id, u.UnitStateID, u.PartIDfrom ffUnit ujoin ffUnitDetail ud on u.id =  ud.unitID where ud.InmostPackageID = @packageIDdeclare @i intdeclare @j intset @i = 0select @j = MAX(ID) from @tempTablebegin tran---Rexwhile @i < @j beginset @i = @i+1 set @UnitID = nullset @CurrUnitStateID = nullset @PartID = null select @UnitID=unitID, @CurrUnitStateID = unitState, @PartID = partID from @tempTable where ID = @iexec @ret = objUNTCheckRouting @UnitID, @xmlPart, @xmlStationif @ret <> 0 or @@ERROR >0beginif @@TRANCOUNT = 1 rollback else commit return @retend endcommit tran



读书人网 >SQL Server

热点推荐