SQL Server 2000 stored procedure types and Instances

Source: Internet
Author: User
Create Table Test (ID int primary key, name char (10 ))

Insert into test values (1, 'test1 ')
Insert into test values (2, 'test2 ')
Insert into test values (3, 'test3 ')
Insert into test values (4, 'test4 ')

1. Returned result set

Create procedure return_result
As
Select * from test

Exec return_result
-- Call
-- ID name
-- 1 test1
-- 2 Test2
-- 3 test3
-- 4 test4

2. Input and Output Parameters

Create procedure input_output
@ ID int,
@ Name char (10) Output
As
Begin
Select @ name = Name from test where id = @ ID
End

-- Call
Declare @ name char (10)
Exec input_output 1, @ name output
Select @ name
-- Output result
-- Name
-- Test1

3. Return Value

-- Each stored procedure can return an integer value with a return statement.
Alter procedure return_value
@ ID int
As
Begin
Declare @ count int -- only integer values can be returned
Select @ COUNT = count (*) from test where id = @ ID
Return @ count
End


-- Call
Declare @ count char (10)
Exec @ COUNT = return_value 1
Select @ count shuliang
-- Structure
-- Shuliang
-- 1

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.