火焰

valeb
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

SQL SERVER 游标格式

Posted on 2024-03-21 11:36  valeb  阅读(20)  评论(0编辑  收藏  举报
 --定义参数
 declare @Row_LevelIndex int
 declare @Row_UserID int
 declare @Row_MemberRight int
 declare @Row_CaptainID	 int
 declare @Row_Score decimal(18,2)
 declare @Row_GroupID int
 declare @Row_ScoreCount decimal(18,2)
 declare @Row_DrawCount int
 declare @Row_AwardScore decimal(18,2)
--定义游标
 declare data_temp cursor for 
       select * from @TEMS_Table  where LevelIndex =2 and MemberRight=4  --数据源 ,* 所代表字段(Index,UserID,MRight,CapID,Score,GId,Count,Draw,Award)与上面定义参数对应
 open data_temp 
		 fetch next from data_temp into @Row_LevelIndex,@Row_UserID,@Row_MemberRight,@Row_CaptainID,@Row_Score ,@Row_GroupID,@Row_DrawCount,@Row_AwardScore  --读取第一行
    while (@@fetch_status = 0) --如果还有记录(行)
	 begin   
	   --写逻辑 eg:
        IF(@Row_LevelIndex>0)
     BEGIN
           --........
     END 
		fetch next from data_temp into  @Row_LevelIndex,@Row_UserID,@Row_MemberRight,@Row_CaptainID,@Row_Score ,@Row_GroupID,@Row_DrawCount,@Row_AwardScore  --读取下一行
	 end 
 close data_temp 
 deallocate data_temp