DF048: A procedure parameter or variable is declared but never used.
Last modified: May 28, 2025
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
Was this page helpful?
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.