标题:对于SroceDB数据库,编写存储过程,输入一个班级编号,返回班级名称,院系, ...
只看楼主
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
结帖率:95.37%
已结贴  问题点数:20 回复次数:7 
对于SroceDB数据库,编写存储过程,输入一个班级编号,返回班级名称,院系,人数。求解哪错了
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




搜索更多相关主题的帖子: 名称 Class output people Student 
2017-05-18 14:43
mywisdom88
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:20 
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上面应该是可以通过的
2017-05-18 22:42
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
得分:0 
回复 2楼 mywisdom88
我的是sql
你给我改的代码也没结果。。
2017-05-19 12:34
mywisdom88
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:0 
不可能,你把你表的结构放上来,同时,放几个数据来。如:
表1(字段1 varchar(10),字段2 int,字段3 numeric(10,2))
表2(字段1 varchar(10),字段2 int,字段3 numeric(10,2))等的格式,我帮你调试

2017-05-22 08:36
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
得分:0 
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
2017-05-22 19:05
mywisdom88
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:0 
/*
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
2017-05-23 09:14
mywisdom88
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:190
帖 子:3125
专家分:8340
注 册:2015-3-25
得分:0 
-- 上面是测试数据
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
2017-05-23 09:22
花脸
Rank: 8Rank: 8
等 级:蝙蝠侠
威 望:9
帖 子:788
专家分:907
注 册:2017-1-4
得分:0 
回复 7楼 mywisdom88
好的 谢谢你、
2017-05-25 21:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-477103-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.099346 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved