编写存储过程访问数据库
对学生-课程数据库,编写存储过程,完成下面功能:
1、统计离散数学的成绩分布情况,即按照分数段统计人数;
create procedure count_sno
@g1 smallint,@g2 smallint --输入分数段
as
declare @cunt int
select @cunt=count(*) from sc
where grade between @g1 and @g2
and cno=(select cno from course where cname='离散数学')
select @g1 成绩1,'---',@g2 成绩2, @cunt 人数
--执行存储过程
exec count_sno 80,100
--带有输出参数的存储过程:
create procedure count_sno
@g1 smallint,@g2 smallint, --输入分数段
@cunt int output --输出参数
as
select @cunt=count(*) from sc
where grade between @g1 and @g2
and cno=(select cno from course where cname='离散数学')
select @g1 成
对学生-课程数据库,编写存储过程,完成下面功能:
1、统计离散数学的成绩分布情况,即按照分数段统计人数;
create procedure count_sno
@g1 smallint,@g2 smallint --输入分数段
as
declare @cunt int
select @cunt=count(*) from sc
where grade between @g1 and @g2
and cno=(select cno from course where cname='离散数学')
select @g1 成绩1,'---',@g2 成绩2, @cunt 人数
--执行存储过程
exec count_sno 80,100
--带有输出参数的存储过程:
create procedure count_sno
@g1 smallint,@g2 smallint, --输入分数段
@cunt int output --输出参数
as
select @cunt=count(*) from sc
where grade between @g1 and @g2
and cno=(select cno from course where cname='离散数学')
select @g1 成