zoukankan      html  css  js  c++  java
  • 简单使用游标插入数据

    --创建数据库

    create proc InsertStudent

    as

    --定义所需要的变量

    declare @SchoolID int
    declare @ClassID int
    declare @StudentID int
    declare @IDNumber int  --条件判断时需要

    begin

    --创建游标

    declare FeeInsertStudent cursor for 
    select stuID,SchID,ClasID from T_School 

    --打开游标

    open FeeInsertStudent 

    --从游标里取出数据给 变量 赋值

    fetch next from FeeInsertStudent into @SchoolID,@ClassID,@StudentID

    --判断有标的状态

    while @@FETCH_STATUS=0

    begin

    --为变量赋值

    set @IDNumber=(select count(*) from T_LeaveSchool where StudentID=@StudentID and SchoolID=@SchoolID and ClassId=@ClassID)
    if(@IDNumber=0)  --判断
    begin
    insert into T_LeaveSchool(StudentID,ClassID,SchoolID)
    values( @StudentID,@ClassID,@StudentID)
    end
    fetch  next from FeeInsertStudent into @SchoolID,@ClassID,@StudentID
    end
    close FeeInsertStudent         --关闭游标
    deallocate FeeInsertStudent                 --撤销游标


    end

  • 相关阅读:
    HTML5中的canvas
    预解释
    asp.net中的CheckBox控件的使用
    jQuery 效果
    常用的 jQuery 事件
    轮播图
    迭代器与生成器
    js对象拷贝
    事件循环、同步异步、宏任务微任务
    Vue 的 keep-alive 组件缓存
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3306502.html
Copyright © 2011-2022 走看看