About 18,900,000 results
Open links in new tab
  1. How to use If condition inside a Case statement?

    Feb 29, 2012 · You can either put another case or use decode (as @madhu suggested): when value in (1000) then null. when user in ('ABC') then user. when area in ('DENVER') then. case when value = 2000 then 'Service1' when value = 3000 then 'Service2' end . else null. end as num_code . select case when value in (1000) then null. when user in ('ABC') then user.

  2. SQL CASE Expression - W3Schools

    The SQL CASE Expression. The CASE expression goes through conditions and returns a value when the first condition is met (like an if-then-else statement). So, once a condition is true, it will stop reading and return the result. If no conditions are true, it …

  3. How do I perform an IF...THEN in an SQL SELECT?

    Sep 15, 2008 · The CASE statement is the closest to IF in SQL and is supported on all versions of SQL Server. SELECT CAST( CASE WHEN Obsolete = 'N' or InStock = 'Y' THEN 1 ELSE 0 END AS bit) as Saleable, * FROM Product

  4. How to Use the CASE Statement in SQL (With Examples)

    Mar 26, 2025 · Syntax of the CASE statement. The CASE statement in SQL follows a straightforward structure that resembles conditional statements in programming languages.. It can be implemented in two ways, depending on how conditions are evaluated: Simple CASE. The simple CASE syntax compares an expression to a set of simple expressions sequentially and returns the result of the first match.

  5. How to Execute an IF…THEN Logic in an SQL SELECT Statement

    May 28, 2024 · We can use either a CASE statement or an IIF() function to implement IF-THEN logic in SQL. In this tutorial, we’ll explore how to implement IF-THEN logic in SQL across various dialects such as SQL Server, MySQL, and PostgreSQL.

  6. Using a SQL Server Case Statement for IF/Else Logic

    Dec 2, 2016 · The case expression is a flexible and effective way of adding conditional logic into a SQL statement. It can often server a function similar to an If/Else construct in other languages.

  7. SQL CASE Expression - SQL Tutorial

    Use the CASE expression to add if-else logic to your query. Use simple CASE expression to evaluate one expression. Use searched CASE expression to evaluate multiple expressions.

  8. SQL CASE Statement Explained with Examples - Database Star

    Jun 2, 2023 · What Does the SQL CASE Statement Do? The CASE statement allows you to perform an IF-THEN-ELSE check within an SQL statement. It’s good for displaying a value in the SELECT query based on logic that you have defined.

  9. How to Use CASE statement in SQL: Explained with Examples

    Jun 28, 2023 · Here’s the general syntax for a simple case statement: WHEN value1 THEN result1. WHEN value2 THEN result2. ... ELSE default_result. With this syntax, if the expression matches value1, the result would be result1. If expression matches value2, the result would be result2, and so on. If there’s no match, the default_result is returned.

  10. CASE - SQL Tutorial

    In this syntax, the CASE statement evaluates each WHEN condition in order, returning the corresponding result when a condition is true. If none of the conditions are true, the statement returns the result specified in the ELSE clause. Let’s take a look at an example.

  11. Some results have been removed
Refresh