Search results
Learn how to use the SQL CASE expression to return different values based on conditions. See syntax, examples and a demo database with the Northwind sample data.
- Try It Yourself
SELECT OrderID, Quantity, CASE WHEN Quantity > 30 THEN 'The...
- The Try-MySQL Editor
SQL Statement: SELECT CustomerName, City, Country FROM...
- Try It Yourself
7 sty 2013 · Using a SELECT statement with a searched CASE expression. Within a SELECT statement, the searched CASE expression allows for values to be replaced in the result set based on comparison values. The following example displays the list price as a text comment based on the price range for a product.
3 wrz 2024 · CASE can be used in any statement or clause that allows a valid expression. For example, you can use CASE in statements such as SELECT, UPDATE, DELETE and SET, and in clauses such as <select_list>, IN, WHERE, ORDER BY, and HAVING. Transact-SQL syntax conventions. Syntax for SQL Server, Azure SQL Database and Azure Synapse Analytics.
7 maj 2017 · The simple way to achieve this goal is to add a CASE expression to your SELECT statement. In this article, we'll introduce you to the syntax, formats, and uses of the CASE expression. The CASE expression is a conditional expression: it evaluates data and returns a result.
26 cze 2023 · We can use CASE in SQL statements such as SELECT, WHERE, and ORDER BY. The CASE statement in the WHERE clause can conditionally filter rows based on defined criteria. The syntax for the CASE statement in the WHERE clause is shown below. The CASE expression matches the condition and returns the value of the first THEN clause.
17 sie 2021 · Explore CASE in SQL and master conditional logic with our comprehensive guide on the CASE statement. Includes practical examples and best practices.
For example, you can use the CASE expression in statements such as SELECT, DELETE, and UPDATE or in clauses such as SELECT, ORDER BY, and HAVING. The following illustrates the simple CASE expression: result_1. result_2. result_3. ... else_result. END Code language: SQL (Structured Query Language) (sql)