I want to compare 2 dates and use CASE in WHERE to implement this logic:
if the end date is larger than 2016-06-30
, the end date should be 6/30/2016
.
However, I'm encountering an error. The error message is
Missing keyword
My code is below:
select start_date, end_date, amount from info
where
case end_date
when to_char(end_date, 'yyyy-mm-dd') > '2016-06-30' then to_date(to_char('2016-06-30'), 'M/D/YYYY') as end_date
end
order by end_date asc
Can you help me?
Best Answer
You could try the following to achieve the result. Your date format string is invalid and the column alias should be placed after the
END
clause of CASE expression.OR