Home

WHEN clauses should not have too many lines of code

Rule description

  • WHEN clauses should not have too many lines of code

 

Non-compliant Code Example

DECLARE @Number int; 
Select 
case when @Number <= 100 then   --Non compliant code (When clause is having line of code more then default defined limit 5)
    case when @Number <= 90 then 
        case when @Number <= 80 then 
            case when @Number <= 70 then 
                case when @Number <= 60 then 
                    case when @Number <= 50 then 
                        case when @Number <= 40 then 
                            case when @Number <= 30 then 
                            20
                            End
                        End
                    End
                End
            End
        End
    End
End

Compliant Code Example

Declare @Number int  
Set @Number = 20
Select 
case when @Number <= 100 then  --Compliant code (When clause is having line of code less then default defined limit 5)
    case when @Number <= 90 then 
        20
    End
End
Visual Expert 2020
 VETSQLRULE74