SQL Server存储过程使用游标
ALTER PROCEDURE [dbo].[B_OF_DATA_PLA]
AS
BEGIN
-- 声明变量
DECLARE @Value1 nvarchar(100),@Value2 datetime,@Value3 datetime
-- 定义游标
DECLARE cE_OF CURSOR FOR
SELECT E_NOF,E_OF_DATE_DEB_PLA,E_OF_DATE_FIN_PLA
FROM E_OF
WHERE E_ETATOF != 'O'
AND E_OF_DATE_DEB_PLA IS NOT NULL AND E_OF_DATE_FIN_PLA IS NOT NULL
-- 打开游标
OPEN cE_OF
-- 取出第一条
FETCH NEXT FROM cE_OF INTO @Value1,@Value2,@Value3
-- 循环
WHILE @@FETCH_STATUS = 0
BEGIN
UPDATE B_OF
SET DPLUSTOT = @Value2,FPLUSTARD = @Value3
WHERE ETATOF != 'O' AND NOF = @Value1;
UPDATE E_OF
SET E_DPLUSTOT = @Value2,E_FPLUSTARD = @Value3
WHERE E_ETATOF != 'O' AND E_NOF = @Value1;
-- 获取下一条记录
FETCH NEXT FROM cE_OF INTO @Value1,@Value2,@Value3
END
CLOSE cE_OF
DEALLOCATE cE_OF
END
本文来自博客园,作者:一纸年华,转载请注明原文链接:https://www.cnblogs.com/nullcodeworld/p/18184827