0

I want to use a CASE statement that uses REGEXP. Currently I am doing something like this:

SELECT `date_of_sale`,
  CASE 
    WHEN `date_of_sale` regexp '[0-9]*-[0-9]*-[0-9]*' then str_to_date(`date_of_sale`, '%m-%d-%Y')
    ELSE
    `date_of_sale`
  END
FROM <TABLE_NAME>

It will gives an error as bellow enter image description here

How to solve this

Divyarajsinh
  • 188
  • 3
  • 9
  • write it as a dynamic query – Ankit Agrawal May 02 '18 at 07:17
  • Remove the backticks - I think your edited doesn’t understand them. Actually, you should never use them. If you have to use them (because an entity name clashes with a keyword), rename the entity to something that doesn’t need them – Bohemian May 02 '18 at 07:20
  • @Divyarajsinh, your codes working perfectly, make query in one line and check, here check it its working fine without error : http://sqlfiddle.com/#!9/90b391/1 check here also working : https://www.eversql.com/sql-syntax-check-validator/ – Anfath Hifans May 02 '18 at 07:24

0 Answers0