数据库(十一)

--根据学生选课题目写一个存储过程,输入教师编号
--判断所教学生的及格率,80分及格,如果及格率超过
--50%,职称上升一级,否则降一级
alter proc pingji
@tno varchar(20)
as
begin
declare @cno varchar(20)
select @cno=cno from Course where Tno=@tno
declare @yxcount int
select @yxcount=count(*) from Score where Cno=@cno and Degree>=70
declare @zcount int
select @zcount=COUNT(*) from Score where Cno=@cno
declare @prof varchar(20)
select @prof=prof from Teacher where Tno=@tno
if @zcount>0
begin
if @yxcount/@zcount>=0.5
begin
if @prof='教授'
begin
print'已经是最高级别,没法再升级了。'
end
if @prof='副教授'
begin
update Teacher set Prof='教授' where Tno=@tno
end
if @prof='讲师'
begin
update Teacher set Prof='副教授' where Tno=@tno
end
if @prof='助教'
begin
update Teacher set Prof='讲师' where Tno=@tno
end
if @prof='后勤'
begin
update Teacher set Prof='助教' where Tno=@tno
end
end
else
begin
if @prof='教授'
begin
update Teacher set Prof='副教授' where Tno=@tno
end
if @prof='副教授'
begin
update Teacher set Prof='讲师' where Tno=@tno
end
if @prof='讲师'
begin
update Teacher set Prof='助教' where Tno=@tno
end
if @prof='助教'
begin
update Teacher set Prof='后勤' where Tno=@tno
end
end
end
else
begin
print'这个老师可能没有教课'
end
end
go
exec pingji '804'

原文地址:https://www.cnblogs.com/mxx0426/p/4099191.html