How to Use Output-type Variable
2016-12-02 12:59
337 查看
--Create Procedure--
if object_id('outputtest')
is not null
drop proc outputtest
Go
create proc outputtest
--This is proc declare, NOT variable declare--
@Output_student_lastfirst nvarchar(500) output,
@Output_Student_number int output
As
--This is variable declare--
declare @FunctionVariable varchar(50)
set @FunctionVariable='9'
select Top 1 @Output_student_number=student_number,@Output_Student_LastFirst=lastfirst
from students
where grade_level=@FunctionVariable
order by newid()
--Select a student on random in grade 9--
select @Output_student_number as
IN_PROC_STDNUM,@Output_Student_LastFirst AS IN_PROC_LASTFIRST
--Create Procedure--
<
4000
span class="TextRun EmptyTextRun SCX155171721" lang="en-us" xml:lang="en-us">
--Output Variables--
declare @output_new_student_lastfirst nvarchar(500)
declare @output_new_Student_number int
exec outputtest
--This is how to contact Procedure only when you have more than 2 variable to output--
@Output_student_lastfirst=@output_new_student_lastfirst output,
@Output_Student_number=@output_new_Student_number output
select
@output_new_Student_number as
OUTPUT_STUDNUM,
@output_new_student_lastfirst as
OUTPUT_LASTFIRST
--Use these 2 variables as criteria--
--Get full info about this student--
select * from students s
where s.lastfirst=@output_new_student_lastfirst and
s.student_number=@output_new_Student_number
-----------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------
--When you have only 1 Output variable in Procedure--
--Create Procedure--
if object_id('outputtest')
is not null
drop proc outputtest
go
create proc outputtest
--this is proc declare, NOT variable declare--
@Output_Student_number int output
As
--this is variable declare--
declare @FunctionVariable varchar(50)
set @FunctionVariable='9'
select Top 1 @Output_student_number=student_number
from students
where grade_level=@FunctionVariable
order by newid()
--select a student on random in grade 9--
select @Output_student_number as
IN_PROC_STDNUM
--Create Procedure--
--Output Variables--
declare @output_new_Student_number int
exec outputtest
--This is how to contact Procedure only when you have only 1 variable to output--
@output_new_Student_number output
select
@output_new_Student_number as
OUTPUT_STUDNUM
--Use these 2 variables as criteria--
--Get full info about this student--
select * from students s
where s.student_number=@output_new_Student_number
if object_id('outputtest')
is not null
drop proc outputtest
Go
create proc outputtest
--This is proc declare, NOT variable declare--
@Output_student_lastfirst nvarchar(500) output,
@Output_Student_number int output
As
--This is variable declare--
declare @FunctionVariable varchar(50)
set @FunctionVariable='9'
select Top 1 @Output_student_number=student_number,@Output_Student_LastFirst=lastfirst
from students
where grade_level=@FunctionVariable
order by newid()
--Select a student on random in grade 9--
select @Output_student_number as
IN_PROC_STDNUM,@Output_Student_LastFirst AS IN_PROC_LASTFIRST
--Create Procedure--
<
4000
span class="TextRun EmptyTextRun SCX155171721" lang="en-us" xml:lang="en-us">
--Output Variables--
declare @output_new_student_lastfirst nvarchar(500)
declare @output_new_Student_number int
exec outputtest
--This is how to contact Procedure only when you have more than 2 variable to output--
@Output_student_lastfirst=@output_new_student_lastfirst output,
@Output_Student_number=@output_new_Student_number output
select
@output_new_Student_number as
OUTPUT_STUDNUM,
@output_new_student_lastfirst as
OUTPUT_LASTFIRST
--Use these 2 variables as criteria--
--Get full info about this student--
select * from students s
where s.lastfirst=@output_new_student_lastfirst and
s.student_number=@output_new_Student_number
-----------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------
--When you have only 1 Output variable in Procedure--
--Create Procedure--
if object_id('outputtest')
is not null
drop proc outputtest
go
create proc outputtest
--this is proc declare, NOT variable declare--
@Output_Student_number int output
As
--this is variable declare--
declare @FunctionVariable varchar(50)
set @FunctionVariable='9'
select Top 1 @Output_student_number=student_number
from students
where grade_level=@FunctionVariable
order by newid()
--select a student on random in grade 9--
select @Output_student_number as
IN_PROC_STDNUM
--Create Procedure--
--Output Variables--
declare @output_new_Student_number int
exec outputtest
--This is how to contact Procedure only when you have only 1 variable to output--
@output_new_Student_number output
select
@output_new_Student_number as
OUTPUT_STUDNUM
--Use these 2 variables as criteria--
--Get full info about this student--
select * from students s
where s.student_number=@output_new_Student_number
相关文章推荐
- How to solve the problem "A project with an Output Type of Class Library cannot be started directly "
- Actionscript 3: How to use describeType() to Save an Object to XML
- How to use variable argument function
- How to use the CONVERSION_EXIT_PARVW_INPUT and CONVERSION_EXIT_PARVW_OUTPUT
- How to use custom type handler (typeHandler) in ibatis 2.3.4
- How To Use Proxy Server To Access Internet at Shell Prompt With http_proxy Variable. [reprint]
- c++ - How to use wstring and wcout to output Chinese words in Xcode? - Stack Overflow
- HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000
- How to read Tcpdump Output | Tcpdump Advanced Use
- How to let "test2.c" use the variable in "test1.c"
- How to Use Temporary Variable
- How to use GitHub with Android Studio
- These codes are How to use Lucence.net
- How to use php serialize() and unserialize()
- Web.py Cookbook 简体中文版 - How to use templates on Google App Engine
- MySQL server version for the right syntax to use near 'TYPE=MyISAM'
- How to Use PeekMessage() Correctly in Windows
- How to use forms in Tapestry 5.
- iOS 后台定位审核被拒How to clarify the purpose of its use in the locatio
- How to Use Hyper-V Snapshot Revert, Apply, and Delete Options