Home

CASE expressions should end with ELSE clauses

Rule description

  • CASE expressions should end with ELSE clauses

 

Non-compliant Code Example

SELECT OrderID, Quantity,
CASE
    WHEN Quantity > 30 THEN 'The quantity is greater than 30'
    WHEN Quantity = 30 THEN 'The quantity is 30'
END AS QuantityText --Non compliant code
FROM OrderDetails;

Compliant Code Example

SELECT OrderID, Quantity,
CASE 
    WHEN Quantity > 30 THEN 'The quantity is greater than 30'
    WHEN Quantity = 30 THEN 'The quantity is 30'
    ELSE 'The quantity is under 30' --Compliant code
END AS QuantityText
FROM OrderDetails;
Visual Expert 2020
 VETSQLRULE62