SA0165 : TOP (100) PERCENT found

The topic describes the SA0165 analysis rule.

Message

TOP (100) PERCENT found

Description

This rule checks for the phrase “TOP (100) PERCENT”.

This phrase has no bearing unless the percentage is less than 100.

This phrase is commonly generated by creating a view in the SQL Server View Designer.

How to fix

Remove the TOP (100) PERCENT clause form the query.

Scope

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

Parameters

Rule has no parameters.

Remarks

The rule does not need Analysis Context or SQL Connection.

Effort To Fix
3 minutes per issue.
Categories

Design Rules, Code Smells

Additional Information

There is no additional info for this rule.

Example Test SQL
SQL
 1SELECT TOP 99 PERCENT
 2           LastName, FirstName, JobTitle, Department
 3FROM       HumanResources.vEmployeeDepartment
 4ORDER BY LastName ASC
 5
 6SELECT TOP 100 PERCENT
 7           LastName, FirstName, JobTitle, Department
 8FROM       HumanResources.vEmployeeDepartment
 9ORDER BY LastName ASC
10
11SELECT TOP 100 PERCENT
12           LastName, FirstName, JobTitle, Department
13FROM       HumanResources.vEmployeeDepartment
14
15SELECT TOP (100) PERCENT  /*IGNORE:SA0165(LINE)*/
16           LastName, FirstName, JobTitle, Department
17FROM       HumanResources.vEmployeeDepartment
18
19SELECT
20        F.Code, 
21        F.CustNum, 
22        SupplierCode = ((SELECT TOP 100 PERCENT S.SupplierCode FROM Supplier S WHERE S.FacilityCode = F.FacilityCode))
23FROM Facility F;

Analysis Results
  Message Line Column
1 SA0165 : TOP (100) PERCENT found. 6 7
2 SA0165 : TOP (100) PERCENT found. 11 7
3 SA0165 : TOP (100) PERCENT found. 22 25
See Also

Other Resources