Reputation: 31
In my SQL script, I have a column of dates in "End_Date" in string format that includes old dates (before 2022) and future dates (March 2022 and onwards). I'm trying to write a CASE statement, where if the future date is greater than today's date, then mark it as "Latest." Basically anything after today's date should be marked as "Latest" Here's part of CASE statement:
CASE WHEN CAST(END_DATE AS DATE) > CURRENT_DATE() THEN "Latest"
I keep getting an error like "generic::out_of_range: Invalid date: '2022-09-30 " when trying to execute the query
Upvotes: 0
Views: 1495
Reputation: 652
Try this:
SELECT
CASE
WHEN CAST('2022-03-18' AS DATE) > CURRENT_DATE() THEN 'Latest'
ELSE 'Old'
END;
Please check the value of END_DATE
. There might be possibility of wrong format of date
Upvotes: 1