1 use StudentManager
 2 go
 3 if exists(select * from sysobjects where name='usp_ScoreQuery2')
 4 drop procedure usp_ScoreQuery2
 5 go
 6 --创建带参数的存储过程
 7 create procedure usp_ScoreQuery2 
 8 @CSharp int,
 9 @DB int
10 as
11     select Students.StudentId,StudentName,C#=CSharp,DB=SQLServerDB
12     from Students
13     inner join ScoreList on Students.StudentId=ScoreList.StudentId
14     where CSharp<@CSharp or SQLServerDB<@DB
15 go
16 --调用带参数的存储过程
17 exec usp_ScoreQuery2 60,65 --按照参数顺序赋值
18 exec usp_ScoreQuery2 @DB=65,@CSharp=60 --参数顺序可以调换

为参数赋默认值

 1 use StudentManager
 2 go
 3 if exists(select * from sysobjects where name='usp_ScoreQuery3')
 4 drop procedure usp_ScoreQuery3
 5 go
 6 --创建带参数的存储过程
 7 create procedure usp_ScoreQuery3 
 8 @CSharp int=60,
 9 @DB int=60
10 as
11     select Students.StudentId,StudentName,C#=CSharp,DB=SQLServerDB
12     from Students
13     inner join ScoreList on Students.StudentId=ScoreList.StudentId
14     where CSharp<@CSharp or SQLServerDB<@DB
15 go
16 --调用带参数的存储过程
17 exec usp_ScoreQuery3 65 --第二个参数没有赋值,则默认
18 exec usp_ScoreQuery3 @DB=65
19 exec usp_ScoreQuery3 default,65 --不使用显示方式赋值
20 exec usp_ScoreQuery3   --两个参数都是用默认参数

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-03-07
  • 2021-08-13
  • 2022-12-23
  • 2022-01-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2022-01-18
  • 2021-07-01
  • 2022-02-20
  • 2022-01-29
相关资源
相似解决方案