Hi @Mikhail Firsov ,
Order BY CASE WHEN warehouse = 'San Fransisco' THEN model
ELSE warehouse END;
Please refer below Order column in the output, the 'X' row should be the last row since it is after 'S' in order.
Order BY CASE WHEN warehouse = 'San Fransisco' THEN quantity
ELSE warehouse END;
You got the 'Conversion failed when converting the varchar value 'San Jose' to data type int' error due to the quantity and warehouse had different date types. One is integer and the other one is varchar.
You could convert the quantity column as below:
Order BY
CASE WHEN warehouse = 'San Fransisco' THEN quantity END,
CASE WHEN warehouse = 'San Jose' THEN warehouse END;
- is the same as the query with
"CASE WHEN warehouse = 'San Fransisco' THEN quantity
ELSE warehouse END"
They are not the same. They had different columns in the output as below:
Please refer below which could be the same:
select warehouse, Product, model, quantity
FROM Inventory
order by CASE WHEN warehouse = 'San Fransisco' THEN cast(quantity as char)
ELSE warehouse END
select warehouse, Product, model, quantity
FROM Inventory
order by
CASE WHEN warehouse = 'San Fransisco' THEN cast(quantity as char)
WHEN warehouse = 'San Jose' THEN warehouse END
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.