sqlserver 存储过程循环遍历结果集,执行相应操作
sqlserver 存储过程循环遍历结果集,执行相应操作
--循环学校表更新每个学校的学校区镇、学段、学校名称 DECLARE @sql NVARCHAR(MAX),@schoolId NVARCHAR(50),@tableName NVARCHAR(150) DECLARE rs CURSOR LOCAL SCROLL FOR select DISTINCT XXDM from dbo.C_GB_SchoolInfo WITH(NOLOCK) OPEN rs FETCH NEXT FROM rs INTO @schoolId WHILE @@FETCH_STATUS = 0 BEGIN IF(@schoolId!=''AND @schoolId IS NOT null) BEGIN SET @tableName= 'Service_PlatformStatistics_'+REPLACE(@schoolId,'-','_') IF EXISTS(SELECT 1 FROM dbo.SysObjects WHERE name=@tableName) BEGIN --这里写业务代码 END END FETCH NEXT FROM rs INTO @schoolId END CLOSE rs
作者:apegu
地址:http://www.cnblogs.com/jiangqw
如果,您认为阅读这篇博客让您有些收获,不妨点击一下推荐按钮。