A stored procedure is a collection of compiled T-SQL statements that can be called at any time, fast and error-prone.
Parameters can be passed, common parameters and output parameters (outputs)
Example 1
Create proc Newpro
@testVarA int,
@testVatB int,
@testSum int Output
As
Begin
set @[email protected][email protected]
End
Call the stored procedure Newpro
DECLARE @testA int
Execute Newpro 100,200, @testA output
Print @testA
Example 2
Create proc TestUser
@testUserName varchar (30),
@testPassWord varchar (30)
As
Begin
declare @testMsg varchar (100)
If @testUserName = ' user1 '
begin
If @testPassWord = ' 123 '
Set @testMsg = ' Welcome entry '
Else
Set @testMsg = ' Sorry, bad password '
End
else if @testUserName = ' user2 '
begin
If @testPassWord = ' abc '
Set @testMsg = ' Welcome entry '
Else
Set @testMsg = ' Sorry, bad password '
End
Else
Set @testMag = ' Please enter the correct user name '
Print @testMsg
End
call the stored procedure testUser
exec testUser ' user1 ', ' 123 '
The new--sql stored process review