ARTICLE DETAIL

资讯详情

深耕网站建设、视觉设计与SEO优化的一线实战洞察。

存储过程循环替代游标

存储过程循环替代游标
select ids=IDENTITY(int,1,1),flag=0,CarNum into #temp 
from CodeN008_Standard.dbo.tbMergeInsdeclare @min_id		int
select @min_id=MIN(ids) from #temp where flag=0while @min_id is not null
beginselect CarNum from #temp where ids=@min_id--业务逻辑update #temp set flag=1 where ids=@min_idselect @min_id=MIN(ids) from #temp where flag=0 and ids>@min_id
end
drop table #temp
返回列表