T-SQL 带参数存储过程
时间:2021-07-01 10:21:17
帮助过:4人阅读
use StudentManager
2 go
3 if exists(
select * from sysobjects
where name
=‘usp_ScoreQuery4‘)
4 drop procedure usp_ScoreQuery4
5 go
6 create procedure usp_ScoreQuery4
--创建带参数的存储过程
7 @AbsentCount int output,
--缺考总人数
8 @FailedCount int output,
--不及格总人数
9 @CSharp int=60,
10 @DB int=60
11 as
12 select Students.StudentId,StudentName,C#
=CSharp,DB
=SQLServerDB
13 from Students
14 inner join ScoreList
on Students.StudentId
=ScoreList.StudentId
15 where CSharp
<@CSharp or SQLServerDB
<@DB --显示结果列表
16 select @AbsentCount=count(
*)
from Students
17 where StudentId
not in(
select StudentId
from ScoreList)
--查询缺考总人数
18 select @FailedCount=count(
*)
from ScoreList
19 where CSharp
<@CSharp or SQLServerDB
<@DB --查询不及格总人数
20 go
调用
1 use StudentManager
2 go
3 --调用带参数的存储过程
4 declare @AbsentCount int,@FailedCount int --首先定义输出参数
5 exec usp_ScoreQuery4 @AbsentCount output,@FailedCount output
6 --使用反馈的结果
7 select 缺考总数=@AbsentCount,不及格总数=@FailedCount
调用时传入输入参数
1 use StudentManager
2 go
3 --调用带参数的存储过程
4 declare @AbsentCount int,@FailedCount int --首先定义输出参数
5 exec usp_ScoreQuery4 @AbsentCount output,@FailedCount output ,65,70
6 --使用反馈的结果
7 select 缺考总数=@AbsentCount,不及格总数=@FailedCount
T-SQL 带参数存储过程
标签:put arp pre out rom lis server 列表 nbsp