MSSQL Codex three MSSQL stored procedure

Source: Internet
Author: User
Tags mssql

--the stored procedure completes the encapsulation of a piece of SQL codeCreate procTrim--parameter list, separated by commas@str varchar(Ten) as--Custom Code SnippetsDeclare @str1 varchar(Ten)Set @str1=LTRIM(RTRIM(@str))Print @str1--Using Stored ProceduresexecTrim'ABC'--' abc '--= = = Stored procedure with output parameters--ask for two numbers andCreate procsum1@num1 int,@num2 int,@result intOutput--indicates that this parameter can take the result out of the stored procedure asSet @result=@num1+@num2Declare @r1 intexecSum11,2,@r1Output--The OUTPUT keyword must be written, or an error is calledPrint @r1--= = = parameter stored procedure with default value, Note: The default value must be the last parameterAlter procMulti@num1 int,@num2 int=TenOutput--The output function is similar to the ref modifier parameter in C # asSet @num2=@num2*@num1Print @num2--test the effect of bringing out valuesDeclare @num int=2execMulti3,@numOutputSelect @num--Test default valuesexecMulti3

Example above, where the stored procedure name cannot exceed 128 characters. A maximum of 1024 parameters are set in each stored procedure, and the Declaration of parameters within the stored procedure requires the keyword declare, and the parameters need to be separated by commas.

Caveats: You cannot delete another stored procedure in one stored procedure, only another stored procedure. A temporary stored procedure with a well font size (#) as the first character of its name, the stored procedure becomes a local temporary stored procedure that resides in the tempdb database and can only be executed by the user who created it;

MSSQL Codex three MSSQL stored procedure

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.