DF048: A procedure parameter or variable is declared but never used.

The topic describes the DF048 T-SQL code analysis rule.

Category

BEST PRACTICE

Message

A procedure parameter or variable is declared but never used.

Description

Avoiding unused parameters and variables is important to maintain code clarity, optimize performance, facilitate maintainability, and reduce unnecessary resource consumption.

Noncompliant code example

CREATE PROCEDURE dbo.ProcDemo (
  @LocationId SMALLINT,
  @LocationName NVARCHAR(255)
)
AS
BEGIN
  SET NOCOUNT ON;
 
  SELECT L.LocationID, L.Name
  FROM Production.Location l;
 
  DECLARE @location_count SMALLINT;
  SET @location_count = (
    SELECT COUNT(*) AS count_row
    FROM Production.Location l
  );
END;
GO

Compliant solution

CREATE PROCEDURE dbo.ProcDemo (
  @LocationId SMALLINT,
  @LocationName NVARCHAR(255) OUTPUT
)
AS
BEGIN
  SET NOCOUNT ON;
  DECLARE @LocName NVARCHAR(255);
 
  SET @LocName = (
    SELECT l.Name
    FROM Production.Location l
    WHERE l.LocationID = @LocationId
    ORDER BY l.Name
      OFFSET 0 ROWS
      FETCH NEXT 1 ROWS ONLY
  );
 
  SET @LocationName = @LocName;
  RETURN @LocationName;
END;
GO

Want to Find out More?

Overview

Overview

Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All Features

All features

Get acquainted with the rich features and capabilities of the Studio in less than 5 minutes.
Request a demo

Request a demo

If you consider employing the Studio for your business, request a demo to see it in action.
Ready to start using dbForge Studio for SQL Server?