Syntax structure:
Create proc name parameter list as Code Snippet
Call:
exec Stored procedure name parameter list
Points:
1 . You can use the output modifier parameter 2. You can use the default values, note that you need to set the last parameter to the default value
Instance:
1 --easy to get started stored procedure procedure2 Create procTri3 @str varchar(Ten)4 as5 Declare @str1 varchar(Ten)6 Set @str1=LTRIM(RTRIM(@str))7 Print @str18 9 --Call: ExecTen execTri'ABC' One --stored procedure output with return value A --ask for two numbers and - Create procsuml - @num1 int , the @num2 int, - @result intOutput--indicates that this parameter can take the result out of the stored procedure - as - Set @result=@num1+@num2 + - Declare @r int + execSuml1,2,@rOutput--The OUTPUT keyword must be written, or an error is called A Print @r at - --parameter stored procedure with default value, Ps: The default value must be the last parameter - Alter procMulti - @num1 int, - @num2 int=TenOutput--The output function is similar to the ref modifier parameter in C # - as in Set @num2=@num2*@num1 - Print @num2 to --test the effect of bringing out values + Declare @num int=2 - execMulti3,@numOutput the Select @num * $
MSSQL stored procedures (long notes, turned out to miss the next)