SQL Server CASE Statement

The SQL Server CASE statement evaluates a list of conditions and returns one of multiple possible result expressions.

Although it’s commonly known as the “CASE statement”, the SQL Server documentation lists it as an expression. Plus it’s referred to as the “CASE expression” in the SQL standard. Some other DBMSs distinguish between the CASE statement and the CASE expression. Either way, here’s a quick rundown on how the “CASE statement” (or CASE expression) works in SQL Server.

Continue reading

Oracle CASE Expression

In Oracle Database, the CASE expression compares a list of conditions and returns one of multiple possible expressions. It allows us to use IF … THEN … ELSE logic in SQL statements without having to invoke procedures.

The CASE expression is included in the SQL standard (ISO/IEC 9075), and most major RDBMSs support it.

Oracle also has a CASE statement that’s very similar to the CASE expression, but with some minor differences.

Continue reading