注册 登录
编程论坛 SQL Server论坛

对于SroceDB数据库,编写存储过程,输入一个班级编号,返回班级名称,院系,人数。求解哪错了

花脸 发布于 2017-05-18 14:43, 2977 次点击
create procedure selec1
(@classnu char(6),
@classna varchar(30)output,
@institu varchar(30)output,
@people int output)
as
select className 班级名称,institute 院系,count(studentNo) 人数 from Class,Student where Class.classNo=Student.classNo
and Class.classNo=@classnu group by className,institute
go
declare @classna varchar(30),@institu varchar(30),@people int
execute selec1 'CP0801',@classna output,@institu output,@people output
select @classna,@institu,@people



select className 班级名称,institute 院系,count(studentNo) 人数 from Class,Student where Class.classNo=Student.classNo
 group by className,institute



只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录
只有本站会员才能查看附件,请 登录

7 回复
#2
mywisdom882017-05-18 22:42
create procedure dbo.selec1
(@classnu char(6),
@classna varchar(30)output,
@institu varchar(30)output,
@people int output)
as
select @classna=className,@institu=institute,@people=count(studentNo) from Class,Student
where Class.classNo=Student.classNo and Class.classNo=@classnu
group by className,institute
go
declare @classna varchar(30),@institu varchar(30),@people int
execute dbo.selec1 'CP0801',@classna output,@institu output,@people output
select @classna,@institu,@people
-- 上面的在MSSQL上面应该是可以通过的
#3
花脸2017-05-19 12:34
回复 2楼 mywisdom88
我的是sql
你给我改的代码也没结果。。
#4
mywisdom882017-05-22 08:36
不可能,你把你表的结构放上来,同时,放几个数据来。如:
表1(字段1 varchar(10),字段2 int,字段3 numeric(10,2))
表2(字段1 varchar(10),字段2 int,字段3 numeric(10,2))等的格式,我帮你调试

#5
花脸2017-05-22 19:05
create procedure selec
(@classnu char(6),
@classna varchar(30)output,
@institu varchar(30)output,
@people int output)
as
select @classna=className,@institu=institute,@people=count(studentNo) from Class,Student
where Class.classNo=Student.classNo and Class.classNo=@classnu
group by className,institute
go
declare @classna varchar(30),@institu varchar(30),@people int
execute selec1 'CP0801',@classna output,@institu output,@people output
select @classna,@institu,@people


classNo    className    institute    grade
CP0801    注册会计08-01班    会计学院    2008
CP0802    注册会计08-02班    会计学院    2008
CP0803    注册会计08-03班    会计学院    2008
CS0701    计算机科学与技术07-01班    信息管理学院    2007
CS0702    计算机科学与技术07-02班    信息管理学院    2007
CS0801    计算机科学与技术08-01班    信息管理学院    2008
ER0701    金融管理07-01班    金融学院    2007
IS0701    信息管理与信息系统07-01班    信息管理学院    2007
IS0801    信息管理与信息系统08-01班    信息管理学院    2008
#6
mywisdom882017-05-23 09:14
/*
create table Class(ClassNo char(6),ClassName varchar(30),Institute varchar(30),Grade datetime)

insert into Class(ClassNo,ClassName,Institute,Grade)
select 'CP0801','注册会计08-01班','会计学院','2008-09-01' union all
select 'CP0802','注册会计08-02班','会计学院','2008-09-01' union all
select 'CP0803','注册会计08-03班','会计学院','2008-09-01' union all
select 'CS0701','计算机科学与技术07-01班','信息管理学院','2007-09-01' union all
select 'CS0702','计算机科学与技术07-02班','信息管理学院','2007-09-01'

*/
select * from Class

/*
create table Student(StudentNo char(6),StudentName varchar(30),Sex char(2),ClassNo char(6))

declare @i int,@stuNo char(6),@stuName varchar(30),@sex char(2),@classNo char(6),@k int
set @i=1

set @k=1
while @k<20
  begin
    set @stuNo='S'+right('00000'+cast(@i as varchar(5)),5)
    set @stuName = '张'+right('00000'+cast(@i as varchar(5)),5)
    set @sex='男'
    set @classNo='CP0801'
    insert into Student(StudentNo,StudentName,Sex,ClassNo) values(@stuNo,@stuName,@sex,@classNo)
    set @i=@i+1
    set @k=@k+1
  end

set @k=1
while @k<25
  begin
    set @stuNo='S'+right('00000'+cast(@i as varchar(5)),5)
    set @stuName = '李'+right('00000'+cast(@i as varchar(5)),5)
    set @sex='女'
    set @classNo='CP0802'
    insert into Student(StudentNo,StudentName,Sex,ClassNo) values(@stuNo,@stuName,@sex,@classNo)
    set @i=@i+1
    set @k=@k+1
  end

set @k=1
while @k<30
  begin
    set @stuNo='S'+right('00000'+cast(@i as varchar(5)),5)
    set @stuName = '王'+right('00000'+cast(@i as varchar(5)),5)
    set @sex='男'
    set @classNo='CP0803'
    insert into Student(StudentNo,StudentName,Sex,ClassNo) values(@stuNo,@stuName,@sex,@classNo)
    set @i=@i+1
    set @k=@k+1
  end

set @k=1
while @k<35
  begin
    set @stuNo='S'+right('00000'+cast(@i as varchar(5)),5)
    set @stuName = '陈'+right('00000'+cast(@i as varchar(5)),5)
    set @sex='女'
    set @classNo='CS0701'
    insert into Student(StudentNo,StudentName,Sex,ClassNo) values(@stuNo,@stuName,@sex,@classNo)
    set @i=@i+1
    set @k=@k+1
  end

set @k=1
while @k<40
  begin
    set @stuNo='S'+right('00000'+cast(@i as varchar(5)),5)
    set @stuName = '刘'+right('00000'+cast(@i as varchar(5)),5)
    set @sex='男'
    set @classNo='CS0702'
    insert into Student(StudentNo,StudentName,Sex,ClassNo) values(@stuNo,@stuName,@sex,@classNo)
    set @i=@i+1
    set @k=@k+1
  end
*/

select * from Student
#7
mywisdom882017-05-23 09:22
-- 上面是测试数据
create procedure dbo.select_class
(@classnu char(6),
 @classna varchar(30)output,
 @institu varchar(30)output,
 @people int output)
 as
 begin
  select @classna=className,@institu=institute,@people=count(studentNo) from Class,Student
  where Class.classNo=Student.classNo and Class.classNo=@classnu
  group by className,institute
 end
 go

 declare @classna varchar(30),@institu varchar(30),@people int
 execute dbo.select_class 'CP0801',@classna output,@institu output,@people output
 select @classna,@institu,@people
#8
花脸2017-05-25 21:32
回复 7楼 mywisdom88
好的 谢谢你、
1