欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

简单实用游标更改数据

程序员文章站 2022-07-21 12:59:53
简单实用游标更改数据   alter proc updatestudent @id int, @id2 int as declare @schooli...

简单实用游标更改数据

 

alter proc updatestudent
@id int,
@id2 int
as
declare @schoolid int
declare @classid int
declare @studentid int
declare @idnumber int
declare @idaaa int
begin
declare feeinsertstudent cursor for 
select stuid,schid,clasid from t_school where id=@id
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)
set @idaaa=(select count(*) from t_leaveschool where id=@id2)
if(@idnumber!=0)
if(@idaaa!=0)
begin
update t_leaveschool set studentid=@studentid,classid=@classid,schoolid=@studentid where id=@id2
end
fetch  next from feeinsertstudent into @schoolid,@classid,@studentid
end
close feeinsertstudent
deallocate feeinsertstudent


end