T-SQL 带参数存储过程

创建带参数的存储过程

 

 

 1 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

 

转载于:https://www.cnblogs.com/Spinoza/p/10052359.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值