CREATE PROC sp_select
@specialty varchar(20),
@grade varchar(20),
@semester varchar(20),
@class1 varchar(20)
AS
begin
declare @s varchar(8000)set @s = 'select a.stu_ID as "学号",a.stu_name as "姓名" '+',['+b.course_name+']=max(case b.course_ID when '+rtrim(a.course_ID)+' then b.course_score end)'
from
course_fix a,course b
where
a.course_ID = b.course_ID
and
a.stu_specialty = @specialty --从课程确定表选择符合专业条件的课程信息
and
a.stu_grade = @grade --从课程确定表选择符合年级条件的课程信息
and
a.semester = @semester --从课程确定表选择符合学期条件的课程信息
+' from stu_info a,scoret b where'
+' a.stu_ID=b.stu_ID '
+' and a.stu_specialty ='''+@specialty+'''' --从stu_info表筛选符合专业条件的学生信息
+' and a.stu_grade ='''+@grade +'''' --从stu_info表筛选符合年级条件的学生信息
+' and a.stu_class ='''+@class1 +'''' --从stu_info表筛选符合班级条件的学生信息
+' and b.semester ='''+@semester +'''' --从scoret 表筛选符合学期条件的成绩信息
+' group by a.stu_ID,a.stu_name'exec (@s)
end
@specialty varchar(20),
@grade varchar(20),
@semester varchar(20),
@class1 varchar(20)
AS
begin
declare @s varchar(8000)set @s = 'select a.stu_ID as "学号",a.stu_name as "姓名" '+',['+b.course_name+']=max(case b.course_ID when '+rtrim(a.course_ID)+' then b.course_score end)'
from
course_fix a,course b
where
a.course_ID = b.course_ID
and
a.stu_specialty = @specialty --从课程确定表选择符合专业条件的课程信息
and
a.stu_grade = @grade --从课程确定表选择符合年级条件的课程信息
and
a.semester = @semester --从课程确定表选择符合学期条件的课程信息
+' from stu_info a,scoret b where'
+' a.stu_ID=b.stu_ID '
+' and a.stu_specialty ='''+@specialty+'''' --从stu_info表筛选符合专业条件的学生信息
+' and a.stu_grade ='''+@grade +'''' --从stu_info表筛选符合年级条件的学生信息
+' and a.stu_class ='''+@class1 +'''' --从stu_info表筛选符合班级条件的学生信息
+' and b.semester ='''+@semester +'''' --从scoret 表筛选符合学期条件的成绩信息
+' group by a.stu_ID,a.stu_name'exec (@s)
end
解决方案 »
- 关于SQL Server 2000 的XML字段类型的查询.
- 求一条SQL语句
- SQL varchar 和 nvarchar插入中文字符 显示???
- 有關job的創建和管理的問題?
- MS SQL 有没有类似一种视图连接方式动态修改的方法??
- 怎样给数据编上序号?
- 在触发器中怎样调用存储过程?请举个例子。
- 在“英文LINUX6。1+英文ORACLE8。1。6”环境下,是否能在数据库中录入“中文“记录,并能在网页上正确显示汉字!
- Oracle7.3中的job执行多次问题?
- 请教大家一个问题:关于数据流量控制问题
- 怎么在表触发器中调用存储过程,并给存储过程中的变量赋值
- 怎样自动或手动清除TempDB所占的容量
在关键字 'from' 附近有语法错误。
set @specialty = '' --专业
set @grade = '' --学年
set @semester = '' --学期
set @class1 = '' --班级
as
begin
declare @s varchar(8000)
set @s='select a.stu_ID as "学号",a.stu_name as "姓名"'select
@s=@s+',['+course_name+']=max(case b.course_ID when '+rtrim(a.course_ID)+' then b.course_score end)'
from
course_fix a,course b
where
a.course_ID = b.course_ID
and
a.stu_specialty = @specialty --从课程确定表选择符合专业条件的课程信息
and
a.stu_grade = @grade --从课程确定表选择符合年级条件的课程信息
and
a.semester = @semester --从课程确定表选择符合学期条件的课程信息
--从课程表选择符合课程种类条件的课程信息set @s=@s+' from stu_info a,scoret b where'
+' a.stu_ID=b.stu_ID '
+' and a.stu_specialty ='''+@specialty+'''' --从stu_info表筛选符合专业条件的学生信息
+' and a.stu_class ='''+@class1 +''''
+' and b.semester ='''+@semester +'''' --从score 表筛选符合学期条件的成绩信息
+' group by a.stu_ID,a.stu_name'--print @sexec(@s)end