SQL CASE

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

The CASE expression is used to implement if-then logic.

Syntax

  • CASE input_expression
     WHEN compare1 THEN result1
    [WHEN compare2 THEN result2]...
    [ELSE resultX]
    END
  • CASE
     WHEN condition1 THEN result1
    [WHEN condition2 THEN result2]...
    [ELSE resultX]
    END

Remarks

The simple CASE expression returns the first result whose compareX value is equal to the input_expression.

The searched CASE expression returns the first result whose conditionX is true.



Got any SQL Question?