SQL Procedures are also very good for scenarios where you want to send input parameters, process information, and return data back for
displaying or reporting purposes. In this example, we'll take a look at how to send two parameters, process the parameters, and send back
the results for further processing. This example will add two integers and return the sum of the two integers.
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE PROCEDURE [dbo].[add2numbers]
SET NOCOUNT ON;
DECLARE @total int
SET @total = @num1 + @num2
Execute the Stored Procedure
/* In a SQL Analyzer window, use the following lines of code to execute the stored procedure.
declare @result int
exec @result= add2numbers @num1=2,@num2=5
select @result as [Sum]
Recommended Books & Training Resources