--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