首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

fetch .into的有关问题

2012-12-15 
fetch ...into的问题use zhuangyiyoucreate table test(sno int not null primary key,grade int)alter ta

fetch ...into的问题
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)


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
select * from test


[其他解释]
引用:
你这红字搞清晰点行不,
DBA姐姐 楼主可以慢慢找嘛

热点排行