Home

CASE structures should not have too many WHEN clauses

Rule description

  • CASE structures should not have too many WHEN clauses

 

Non-compliant Code Example

SELECT Id,
       CASE statecode
			WHEN 101 THEN 'ABC' 
			WHEN 201 THEN 'DEF' 
			WHEN 301 THEN 'MNP' 
			WHEN 401 THEN 'PQR'
			WHEN 501 THEN 'XYZ'
			WHEN 601 THEN 'IJK'
			WHEN 701 THEN 'UVW'
			WHEN 801 THEN 'FGH'
			WHEN 901 THEN 'PLM'
			WHEN 1001 THEN 'QRE' --Non compliant code (Number of when clauses are equal or more then default defined limit 10)
			WHEN 1101 THEN 'STR' --Non compliant code (Number of when clauses are equal or more then default defined limit 10)
			Else 'Unknown'
		END
FROM cars
WHERE Id < 1000
Visual Expert 2020
 VEPLSQLRULE98