CASE [ expression ]. WHEN condition_1 THEN result_1 WHEN condition_2 THEN result_2 …
Например, выражение CASE можно использовать в таких инструкциях, как SELECT, UPDATE, DELETE и SET, а также в таких предложениях
CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 WHEN conditionN THEN resultN ELSE result END; Demo Database.
And example: 244 proc sql; 245 select case when sex='M' then 0 246 else 1 end as Total whatsit
WHEN ListPrice >= 250 and ListPrice < 1000 THEN 'Under $1000'. ELSE 'Over $1000' END FROM Production.Product. ORDER BY ProductNumber. But there is SQL error, missing important words before FROM. What is the blueprint for us to use case if I want to select all the columns ?
SELECT Store_Name, CASE Store_Name WHEN 'Los Angeles' THEN Sales * 2 WHEN 'San Diego' THEN Sales * 1.5 ELSE Sales END "New Sales", Txn_Date FROM Store_Information
Very often you want to perform IF statement in SELECT and replace one value with another. In SQL we cannot use IF in SELECT clause however we can achieve the same result using CASE WHEN THEN ELSE. In the below example I will use a very simple example where I will divide 7 days into 3 parts...
SELECT CASE Expression. When expression1 Then Result1.
select sal, case when sal < 2000 then 'category 1' when sal < 3000 then 'category 2' when sal < 4000 then 'category 3' else 'category 4' end from emp; E.g.: The requirement is to find out the count of employees for various conditions as given below. There are multiple ways of getting this output.
SELECT ProductName, Manufacturer, CASE ProductCount WHEN 1 THEN 'Товар заканчивается' WHEN 2 THEN 'Мало товара' WHEN 3 THEN 'Есть в наличии' ELSE 'Много товара' END AS EvaluateCount FROM Products. Здесь значения столбц�� ProductCount последовательн��...