This simple stored procedure calculates the area of a rectangle using length and breadth—an ideal example for beginners. It’s designed to spark interest in those just starting their journey with SQL Server and T-SQL programming.
/********************************************************************
Description : Stored Procedure to calculate the area of a rectangle
Definition :
The area of a rectangle is calculated using the formula:
Area = Length × Breadth
It represents the space **inside** the rectangle.
Parameters :
- Accepts Length and Breadth as input parameters
- Calculates the area using the formula Length × Breadth
- Returns the result via OUTPUT parameter
********************************************************************/
CREATE PROCEDURE dbo.Calculate_Rectangle_Area
( @Length FLOAT,
@Width FLOAT,
@Area FLOAT OUTPUT)
AS
BEGIN
SET NOCOUNT ON;
SET @Area = @Length * @Width;
END
Execution of Stored Procedure
USE [BI_Reporting]
GO
DECLARE @return_value int,
@Area float
EXEC @return_value = [dbo].[Calculate_Rectangle_Area]
@Length = 20,
@Width = 40,
@Area = @Area OUTPUT
SELECT @Area as 'Area of Rectangle'
GO
