SQL Server 结果集循环处理的 避免游标处理方法
2013-04-02 14:31
435 查看
结果集循环,避免使用游标的方法(游标的性能一般不好): 创建一个临时表:
declare @tempTable table(ID int identity(1,1), unitID int, unitState int, partID bigint) insert into @tempTable select distinct u.id, u.UnitStateID, u.PartID from ffUnit u join ffUnitDetail ud on u.id = ud.unitID where ud.InmostPackageID = @packageID declare @i int declare @j int set @i = 0 select @j = MAX(ID) from @tempTable begin tran---Rex while @i < @j begin set @i = @i+1 set @UnitID = null set @CurrUnitStateID = null set @PartID = null select @UnitID=unitID, @CurrUnitStateID = unitState, @PartID = partID from @tempTable where ID = @i exec @ret = objUNTCheckRouting @UnitID, @xmlPart, @xmlStation if @ret <> 0 or @@ERROR >0 begin if @@TRANCOUNT = 1 rollback else commit return @ret end end commit tran
相关文章推荐
- ssis:向同一sql server表中导入循环导入多张access表时,需要增加计算列的处理方法。
- mysql中游标循环处理结果集时判断游标是否到结果最后
- SQL Server 游标处理 循环
- sql server 使用循环和临时表处理数据 而不用游标
- SQL Server在存储过程中编写事务处理代码的三种方法
- SQL Server 中游标的使用原理与方法
- oracle 隐式游标,显示游标,游标循环,动态SELECT语句和动态游标,异常处理,自定义异常,
- javascript 处理HTML元素必须避免使用的一种方法
- sql server 还原数据库备份失败:已到文件结尾(38)3203处理方法
- SQL Server 中用While循环替代游标(Cursor的解决方案
- SQL Server 2008R2部署程序集时"Clr 程序集必须具有指定的主文件"的处理方法
- SQL Server 2008置疑处理方法
- SQL Server :While循环替代游标,性能提升
- 逐行处理数据时避免死循环
- SQL server 日志太大的处理方法
- MySQL通过游标来实现通过查询结果集循环
- 避免在 SQL Server 中盲目地追求一句处理
- 巧用while循环避免执行除了异常处理的的另一个处理机制
- SQL Server代理服务无法启动的处理方法(转载)
- 利用游标返回结果集的的例子(Oracle 存储过程)JAVA调用方法和.NET调用方法