首页 > 代码库 > Sql 使用游标
Sql 使用游标
DECLARE data_cursor CURSORFOR WITH T0 AS ( SELECT COUNT(f.DeptID) SubmitCount , f.DeptID FROM biz.FormCollect f INNER JOIN biz.Results r ON f.IID = r.ObjectID INNER JOIN biz.NumberLimit n ON n.DeptID = f.DeptID WHERE r.[Status] = 1 GROUP BY f.DeptID ), T1 AS ( SELECT b.BatchID , c.BatchName , n.IID , n.DeptName , t0.SubmitCount FROM biz.FormCollect f INNER JOIN biz.BatchRelationShips b ON f.IID = b.FormID INNER JOIN T0 ON T0.DeptID = f.DeptID INNER JOIN biz.NumberLimit n ON n.DeptID = t0.DeptID INNER JOIN bas.ChooseBatch c ON c.IID = b.BatchID WHERE c.ModuleID = 2 ) SELECT DISTINCT IID , BatchID , SubmitCount FROM T1GoOPEN data_cursorDECLARE @IID INT ;DECLARE @BatchID INT ;DECLARE @SubmitCount INT ;WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM data_cursor INTO @IID, @BatchID, @SubmitCount PRINT @IID; PRINT @BatchID; PRINT @SubmitCount; PRINT ‘‘; INSERT INTO biz.NumberLimitCount ( NumberLimitID , BatchID , LimitCount , CurrentCount , ModifyTime ) VALUES ( @IID , -- NumberLimitID - int @BatchID , -- BatchID - int 0 , -- LimitCount - int @SubmitCount , -- CurrentCount - int GETDATE() -- ModifyTime - datetime ) END CLOSE data_cursorDEALLOCATE data_cursor
Sql 使用游标
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。