Skip to content

SA0029 : Input parameter never used

Unused parameters in stored procedures or functions can lead to confusion, reduced code readability, and maintenance challenges.

In SQL Server, stored procedures and functions can have parameters that may not be utilized within the body of their respective code blocks. When parameters are declared but not used, it results in unnecessary complexity within the database schema. This issue can lead to confusion, increased maintenance efforts, and it detracts from code readability.

For example:

-- Example of a stored procedure with unused parameters
CREATE PROCEDURE GetEmployeeDetails
@EmployeeID INT,
@DepartmentID INT
AS
BEGIN
SELECT Name, Position FROM Employees WHERE EmployeeID = @EmployeeID;
END;

In this example, @DepartmentID is declared but never used. Such unused parameters do not directly affect performance but add unwanted clutter, misleading developers and making future code modifications cumbersome.

  • Unused parameters increase the complexity of stored procedures or functions without any functional benefit.

  • They may cause confusion about the procedure’s or function’s actual input requirements and make future maintenance trickier.

Remove unused input parameters from stored procedures or functions to optimize code clarity and maintainability.

Follow these steps to address the issue:

1.Analyze the stored procedure or function to identify parameters that are declared but not used within the code block. Use sp_helptext or inspect the procedure directly in SQL Server Management Studio (SSMS).

2.Edit the stored procedure or function to remove the unused parameters. In SSMS, right-click the procedure and select Modify to open the SQL script for editing.

3.Delete the unused parameter from the procedure’s parameter list and any line of code where it might have been initialized or commented out.

4.Save and recompile the procedure/function by executing the ALTER statement to ensure that your changes take effect.

5.Test the modified procedure/function to ensure it still functions as expected without the unused parameter.

For example:

-- Original stored procedure with an unused parameter
CREATE PROCEDURE GetEmployeeDetails
@EmployeeID INT,
@DepartmentID INT
AS
BEGIN
SELECT Name, Position FROM Employees WHERE EmployeeID = @EmployeeID;
END;
-- Modified procedure without the unused parameter
ALTER PROCEDURE GetEmployeeDetails
@EmployeeID INT
AS
BEGIN
SELECT Name, Position FROM Employees WHERE EmployeeID = @EmployeeID;
END;

The rule has a Batch scope and is applied only on the SQL script.

Rule has no parameters.

The rule does not need Analysis Context or SQL Connection.

2 minutes per issue.

Design Rules, Code Smells

There is no additional info for this rule.

CREATE PROCEDURE Production.uspGetList
@Product varchar(40)
, @VendorCode varchar(20) -- parameter is not used
, @VendorCode2 varchar(20) -- parameter is not used, but the rule is suppressed because this comment contains 'IGNORE:SA0029' text.
, @MaxPrice money
, @Input int -- parameter is only assigned, but not used
AS
SET NOCOUNT ON;
SET @Input = 0
SELECT p.[Name] AS Product, p.ListPrice AS 'List Price'
FROM Production.Product AS p
WHERE s.[Name] LIKE @Product AND p.ListPrice < @MaxPrice;
 MessageLineColumn
1SA0029 : The input parameter @VendorCode never used.33
2SA0029 : The input parameter @Input never used.66

Analysis Rules