SQL stored procedure usage experience

Source: Internet
Author: User

 
Example 1: query the stored procedure of all data in a data table

Query the Stored Procedure statement in Analyzer:
Declare @ retval int
Execute sp_showalluserinfo @ retval

Stored Procedure statement in Enterprise Manager:
Create procedure sp_showalluserinfo @ retval int output
As
Select * From userlist
If @ rowcount <= 0
Return 0
Else
Return 1
Go

 

Example 2: query the stored procedure of a specified field in a data table

Query the Stored Procedure statement in Analyzer:
Execute sp_searchuserinfo null, 'xqf222 @ 163.com'

Stored Procedure statement in Enterprise Manager:
Create procedure sp_searchuserinfo
(
@ Username nvarchar (20 ),
@ Useremail nvarchar (60)
)
As

If Len (@ username) = 0 or Len (@ useremail) = 0
Select * From userlist
Else
If Len (@ username)> 0 and Len (@ useremail)> 0
Select * From userlist where username = @ username
Else
If Len (@ username)> 0
Select * From userlist where username = @ username
Else
Select * From userlist where useremail = @ useremail
Go

 

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.