I have a field that is a decimal date (YYYYMMDD). I need to find all
records that are a year or less old. Since date are so easy, I am
trying to do:
WHERE DATE(SUBSTR(CHAR(A.CPADDT),1,4) CONCAT '-' CONCAT
SUBSTR(CHAR(A.CPADDT),5,2) CONCAT '-' CONCAT
SUBSTR(CHAR(A.CPADDT),7,2)) > CURRENT_DATE - 1 YEAR
This works great in the SELECT portion. When I put it in the WHERE
section I get “Selection error involving field *N.”
Any ideas of what I am doing wrong?
Selection error involving field *N.indicates you have an invalid date in your table.Check the job log for a
CPD4019. The cause will include the relative record number of the bad date.You can also use the Jon Skeet’s solution inline like so
and not have to worry about date conversion errors at all in addition to the other benefits.