1. 程式人生 > >SQLServer --自定義帶輸入引數的儲存過程

SQLServer --自定義帶輸入引數的儲存過程

帶輸入引數的儲存過程

這裡寫圖片描述

這裡寫圖片描述

在引數中新增預設值

這裡寫圖片描述

這裡寫圖片描述

use StuManageDB
go

if exists(select * from sysobjects where name='usp_ScoreQuery1')
drop procedure usp_ScoreQuery1
go

create procedure usp_ScoreQuery1
--引數自定義預設值
@CSharp int=60,@DB int=60

as
    select Students.StudentId,StudentName,CSharp,SQLServerDB
    from Students
    inner
join ScoreList on Students.StudentId = ScoreList.StudentId where CSharp<@CSharp or SQLServerDB<@DB go --四種呼叫方式 exec usp_ScoreQuery1 --倆個引數都使用預設值 exec usp_ScoreQuery1 @DB=80 --第二個引數沒有賦值,則預設 exec usp_ScoreQuery1 default,80 --不使用顯示方式賦值 exec usp_ScoreQuery1 80