SQL,创建一个存储过程,接收学生姓名后返回该学生的课程总成绩。怎样做?

如题所述

我给你写个例子:
create procedure getTotal
@studentname varchar(6),
@zongchengji int output //output表示输出参数
as
//假如,表中已给出总成绩
select @zongchengji=total from table where name=@studentname
go
这个存储过程大概是这样追问

太大概了。你就看看我的问题在哪里好了:
use student
go
if exists
(select name from sysobjects
where name='stu_info_pro' and type='p')
drop proc stu_info_pro
go
use student
go
create proc stu_info_pro
(@sname char(10))
as
select sum(result)'总成绩'
go
select a.student_name,b.result
from result_info a join student_info b
on a.student_id=b.student_id
and student_name=@sname
go

追答

你最终要得到的结果是学生姓名和总成绩,你光查询出来了,但没有显示呀。你可以定义一个变量来接收你查询的结果,然后再打印出来就行了。比如:
declare @name varchar(8),@sum int
select
@name=a.student_name,@sum=b.result //定义变量接收查询的结果
from result_info a join student_info b
on a.student_id=b.student_id
and student_name=@sname
print @name+convert(varchar(8),@sum) //在存储过程里面打印

追问

其实我的查询过程都有问题。 并没有显示命令已完成。 不过还是谢谢你,现在我已经解决了。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-09
姓名=@aa 我有学生表和成绩表.不知道怎么做的.谢谢! 两个表靠什么字段关联? 还有这个靠一个sql语句就能跑出来,不用存储过程追问

我汗。。。 如果是SQL的话,应该是student_id吧,如果你的表建立的没得问题的话。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网