I have a table which contains products, a start date and an interval value :
product_name start_date expiry_period
Domain Reg
You need to test for each one individually:
select product_name, start_date, expiry_period,
(case when expiry_period like '%day'
then DATE_ADD(start_date, INTERVAL expiry_period + 0 DAY) as end_date
when expiry_period like '%week'
then DATE_ADD(start_date, INTERVAL expiry_period + 0 WEEK) as end_date
when expiry_period like '%month'
then DATE_ADD(start_date, INTERVAL expiry_period + 0 MONTH) as end_date
when expiry_period like '%year'
then DATE_ADD(start_date, INTERVAL expiry_period + 0 YEAR) as end_date
end)
from tbl_products;
The arithmetic (+ 0
and * 7
) converts the string to a number.