sqlserver 游标格式 东师理想

DECLARE @JGID_TEMP VARCHAR(36);
SET @JGID_TEMP = '';
DECLARE E1cursor cursor  FOR SELECT JG_ID FROM T_RS_EMPLOYEE;

OPEN E1cursor    /* 打开游标 */  
FETCH NEXT from E1cursor   INTO @JGID_TEMP  -- 读取第1行数据  
WHILE @@FETCH_STATUS = 0     -- 用WHILE循环控制游标活动  
BEGIN     
    
    PRINT @JGID_TEMP
    FETCH NEXT from E1cursor   INTO @JGID_TEMP  -- 读取第1行数据  
END
CLOSE E1cursor              -- 关闭游标  
DEALLOCATE E1cursor          -- 删除游标 
原文地址:https://www.cnblogs.com/cczhoufeng/p/3092070.html