use zhuangyiyou
create table test(sno int not null primary key,grade int)
alter table test add rankk char(1) check(rankk in('A','B','C','D','E'))
insert into test values(1,88,'B')
declare cur_test cursor for select *from test for update of rankk
open cur_test
declare @sno int
declare @grade int
declare @rankk char(1)
fetch next from cur_test into @sno,@grade,@rankk
while(@@FETCH_STATUS=0)
begin
if(@grade>=90) update test set rankk='A' where sno=@SNO
if(@grade>=80 and @grade<90) update test set rankk='B' where sno=@SNO
if(@grade>=70 and @grade<80) update test set rankk='C' where sno=@SNO
if(@grade>=60 and @grade<70) update test set rankk='D' where sno=@SNO
if(@grade>=0 and @grade<60) update test set rankk='E' where sno=@SNO
fetch next from cur_test into @sno,@grade,@rankk
end
close cur_test
哪里有错啊。。。。。
------最佳解决方案--------------------
use zhuangyiyou
create table test(sno int not null primary key,grade int)
alter table test add rankk char(1) check(rankk in('A','B','C','D','E'))
insert into test values(1,88,'B')
declare cur_test cursor for select * from test for update of rankk --此处红色'*'查询必须写出列名而不能用*代替
open cur_test
declare @sno int
declare @grade int
declare @rankk char(1)
fetch next from cur_test into @sno,@grade,@rankk
while(@@FETCH_STATUS=0)
begin
if(@grade>=90) update test set rankk='A' where sno=@SNO
if(@grade>=80 and @grade<90) update test set rankk='B' where sno=@SNO
if(@grade>=70 and @grade<80) update test set rankk='C' where sno=@SNO
if(@grade>=60 and @grade<70) update test set rankk='D' where sno=@SNO
if(@grade>=0 and @grade<60) update test set rankk='E' where sno=@SNO
fetch next from cur_test into @sno,@grade,@rankk
end
close cur_test
------其他解决方案--------------------
你这红字搞清晰点行不,
------其他解决方案--------------------
该回复于2012-11-06 21:19:35被管理员删除
------其他解决方案--------------------
use study_db
if exists(select name from sys.objects where name='test'and type='u')
drop table test
create table test(sno int not null primary key,grade int)
alter table test add rankk char(1) check(rankk in('A','B','C','D','E'))
insert into test values(1,88,'B')
declare cur_test cursor for select sno,grade,rankk from test open cur_test
declare @sno int
declare @grade int
declare @rankk char(1)
fetch next from cur_test into @sno,@grade,@rankk
while(@@FETCH_STATUS=0)