Yahoo Poland Wyszukiwanie w Internecie

Search results

  1. 15 wrz 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. You only need to use the CAST operator if you want the result as a Boolean value. If you are happy with an int, this works: SELECT CASE.

  2. SQL CASE Examples. The following SQL goes through conditions and returns a value when the first condition is met: Example. SELECT OrderID, Quantity, CASE. WHEN Quantity > 30 THEN 'The quantity is greater than 30'. WHEN Quantity = 30 THEN 'The quantity is 30'. ELSE 'The quantity is under 30'. END AS QuantityText.

  3. 28 maj 2024 · In this article, we explored different options for executing IF-THEN logic in a SQL SELECT statement. These options include using CASE, IIF(), and CHOOSE(). Furthermore, if we want a query that’s used in almost every dialect, we must choose the CASE statement.

  4. 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;

  5. 2 cze 2023 · You can probably write two CASE statements to display it: SELECT CASE WHEN MOD(yourcolumn, 2)=0 THEN yourcolumn ELSE null END AS evenvalue, CASE WHEN MOD(yourcolumn, 2)=1 THEN yourcolumn ELSE null END AS oddvalue FROM yourtable;

  6. 28 cze 2023 · An example use of case with SUM is: SELECT SUM(CASE WHEN column_name = 'value1' THEN amount_column ELSE 0 END) AS sum_of_value1_amount, SUM(CASE WHEN column_name = 'value2' THEN amount_column ELSE 0 END) AS sum_of_value2_amount FROM table_name;

  7. The basic syntax of the SQL CASE statement is as follows: CASE. WHEN condition1 THEN result1. WHEN condition2 THEN result2. ... ELSE resultN. END. In this syntax, the CASE statement evaluates each WHEN condition in order, returning the corresponding result when a condition is true.

  1. Ludzie szukają również