I read ORDER BY condition and How to add condition in 'order by'? but these don’t answer to my issue.
I have 2 datetime columns called CREATION_DATE and UPDATE_DATE.
I want to sort (using ORDER BY clause) by :
-
CREATION_DATEifCREATION_DATE = UPDATE_DATEor
-
UPDATE_DATEin other case.
I wrote
SELECT * FROM Table1
ORDER BY
CASE Table1.CREATION_DATE
WHEN Table1.CREATION_DATE = Table1.UPDATE_DATE THEN Table1.CREATION_DATE
ELSE Table1.UPDATE_DATE
END ASC
but it does not work, I get an error at the = symbol.
I tried with other operators… Of course, I make mistake but I don’t know if is correct to use operators in WHEN statement.
Is not accepted operators in WHEN ?
Thank you
try
or simpler
since you want to order by
UPDATE_DATEonly if it is equal toCREATION_DATE. In that case you could order byUPDATE_DATEtoo. In other cases you want to oder byUPDATE_DATE. So just only order by that. It is the same.