DF085: The CASE statement is used without the ELSE clause.

The topic describes the DF085 T-SQL code analysis rule.

Category

STYLE

Message

The CASE statement is used without the ELSE clause.

Description

It is recommended to add the ELSE clause to the CASE expression with either a default action, or a comment explaining the reason an action is not taken.

Additional information

Using a CASE statement without the ELSE clause can lead to unexpected results or NULL values when none of the specified conditions are met, potentially causing errors or undesired behavior in queries.

Noncompliant code example

SELECT
  CASE
    WHEN @id = 12 THEN 'YES'
  END

Compliant solution

SELECT
  CASE
    WHEN @id = 12 THEN 'YES'
    ELSE NULL
  END