SQLServer--帶輸出引數的儲存過程
阿新 • • 發佈:2018-12-31
帶輸出引數的過程
use StuManageDB
go
if exists(select * from sysobjects where name='usp_ScoreQuery3')
drop procedure usp_ScoreQuery3
go
create procedure usp_ScoreQuery3
@AbsentCount int output,
@FailedCount int output,
@CSharp int=60,
@DB int=60
as
select Students.StudentId,StudentName,CSharp,SQLServerDB
from Students
inner join ScoreList on Students.StudentId=Students.StudentId
where CSharp<@CSharp or SQLServerDb<@DB
--查詢缺考人數
select @AbsentCount=Count(*) from Students
where StudentId not in(select StudentId from ScoreList)
--查詢不及格人數
select @FailedCount=Count(*) from ScoreList
where CSharp<@CSharp or SQLServerDB<@DB
go
declare @AbsenCount int,@FailedCount int --定義輸出引數
exec usp_ScoreQuery3 @AbsenCount output,@FailedCount output
select 缺考總數[email protected],不及格總數[email protected]