DECLARE cursor_a CURSOR --声明游标
FOR
SELECT name
FROM cc_tb_cfg_operator
WHERE oper_id > 0
--order by sDomainCode
go--缺少go将报错:DECLARE CURSOR must be the only statement in a query batch
OPEN cursor_a --打开游标
DECLARE @domainCode VARCHAR(11), @message VARCHAR(80)
FETCH cursor_a
INTO @domainCode --提取游标数据
WHILE @@sqlstatus = 0
BEGIN
--PRINT " "
--SELECT @message = "----- Books by Author: " + @domainCode
--PRINT @message
--to do something.....
-- Get the next cur.
FETCH cursor_a
INTO @domainCode
END
CLOSE cursor_a
DEALLOCATE CURSOR cursor_a --删除游标