SQL 游标 指针

DECLARE @radioScoreRate decimal
DECLARE @checkScoreRate decimal
DECLARE @judgeScoreRate decimal
DECLARE @radioQty decimal
DECLARE @checkQty decimal
DECLARE @judgeQty decimal
DECLARE @examId uniqueidentifier
DECLARE My_Cursor CURSOR
FOR (SELECT examId,radioScoreRate,checkScoreRate,judgeScoreRate,radioQty,checkQty,judgeQty FROM El_ExamInfo)
OPEN My_Cursor; --打开游标
FETCH NEXT FROM My_Cursor INTO @examId,@radioScoreRate,@checkScoreRate,@judgeScoreRate,@radioQty,@checkQty,@judgeQty;
WHILE @@FETCH_STATUS = 0
BEGIN

update El_ExamInfo set singleRadioScore=@radioScoreRate/case when @radioQty>0 then @radioQty else 1 end ,singleCheckScore=@checkScoreRate/case when @checkQty>0 then @checkQty else 1 end , singleJudgeScore=@judgeScoreRate/case when @judgeQty>0 then @judgeQty else 1 end where examId=@examId

FETCH NEXT FROM My_Cursor INTO @examId,@radioScoreRate,@checkScoreRate,@judgeScoreRate,@radioQty,@checkQty,@judgeQty;
END
DEALLOCATE My_Cursor;

posted @ 2017-10-31 10:23  —阿峰—  阅读(1683)  评论(0编辑  收藏  举报