Search results
Learn how to use the SQL CASE expression to check conditions and return values like an if-then-else statement. See examples with the Northwind sample database and try them yourself.
- Try It Yourself
Get your own SQL server SQL Statement: SELECT OrderID,...
- The Try-MySQL Editor
Get your own SQL server SQL Statement: Edit the SQL...
- Try It Yourself
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.
28 lut 2023 · CASE w SQL Server to instrukcja wyboru porównywalna do instrukcji warunkowej MsSQL IIF THEN ELSE w innych językach programowania. W jaki sposób z niej skorzystać? CASE w SQL możemy wykonać na dwa sposoby. Poniżej przedstawiam schematy działania instrukcji. Pierwsza konstrukcja CASE polega na przypisaniu wyniku do wartości.
20 kwi 2021 · In the T-SQL scripting language, you can use the SQL CASE statement to evaluate a condition and return one or more result expressions. This SQL Tutorial will teach you when and how you can use CASE in T-SQL statements.
13 cze 2021 · Here are the CASE expression examples from the PostgreSQL docs (Postgres follows the SQL standard here): SELECT a, CASE WHEN a=1 THEN 'one' WHEN a=2 THEN 'two' ELSE 'other' END FROM test; or. SELECT a, CASE a WHEN 1 THEN 'one' WHEN 2 THEN 'two' ELSE 'other' END FROM test;
11 lut 2020 · Using the SQL Server CASE statement to get aggregations for subsets in different columns. The CASE statement can be very helpful when there is a need to aggregate the data for different subsets and represent the results for each subset in separate columns.
This tutorial shows you how to use the SQL Server CASE expression to add if-else logic to SQL queries with many practical examples.