- 新しい順
- 投票が多い順
- コメントが多い順
Hi,
the issue is that you are trying to cast the word ‘None’ to a date, which of course will throw an error.
You should add a clause which exclude this value, like where enddate != (is not) ‘None’ or similar, not knowing the context of the query (database, sql, or something else).
Hope it helps and if it does I would appreciate answer to be accepted so that community can benefit for clarity, thanks ;)
You can use a CASE statement to handle the 'None' values before casting the date. In this example, I'll replace 'None' with a NULL value, then proceed with your original query.
date_format(
cast(
CASE
WHEN c.enddate = 'None' THEN NULL
ELSE c.enddate
END as date
),
'%M'
) as "Month",
date_format(
cast(
CASE
WHEN c.enddate = 'None' THEN NULL
ELSE c.enddate
END as date
),
'%Y'
) as "Year"
This query first checks if c.enddate is 'None', and if so, it replaces it with a NULL value. Then it proceeds with the original cast and date_format functions to extract the Month and Year.