游标简单使用方法(全)

DECLARE MyCusror11 CURSOR FOR Select [学生姓名],[学费],[住宿费],[伙食费],[教辅材料费] From [OneCard_HuangGangZhongXue].[dbo].[数据导入20210916] --创建游标
OPEN MyCusror11 --打开游标

DECLARE 
@name nvarchar(255), --声明游标变量
@xuefei decimal,
@zhusufei decimal,
@huosifei decimal,
@jiaofufei decimal 
Fetch next From MyCusror11 Into @name,@xuefei,@zhusufei,@huosifei,@jiaofufei

While(@@Fetch_Status = 0)
    Begin
        --读取游标数据
        --Select @title = Convert(nvarchar(100),@title),@mytype= Convert(nvarchar(100),@mytype)
        update [OneCard_HuangGangZhongXue].[dbo].Payment_OfflinePay set XueFei=@xuefei,ZhuSuFei=@zhusufei,HuoShiFei=@huosifei,JiaoCaiFei=@jiaofufei where Name=@name

        --打印游标数据
        --PRINT @title+','+Cast(@mytype as varchar(20))

        --继续下一个游标读取
        Fetch next From MyCusror11 Into @name,@xuefei,@zhusufei,@huosifei,@jiaofufei
    End
Close MyCusror11
Deallocate MyCusror11

 

上一篇:C#中的委托(一)


下一篇:mysql第二天初学小结