3

I'm trying to add an integer to a date but I get the following error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(wp.OrderDate, INTERVAL WPProduct.Duration DAY) AS ExpiryDate FROM wp' at line 6

SELECT 
wp.customers_id, 
wp.OrderDate, 
wp.products_id,
WPProduct.Duration,
DATE_ADD (wp.OrderDate, INTERVAL WPProduct.Duration DAY) AS ExpiryDate
FROM wp 
INNER JOIN WPProduct ON WPProduct.products_id = wp.products_id
WHERE wp.customers_id = 2
4
  • post your tables' schmas Commented Dec 23, 2015 at 15:56
  • Is WPProduce.Duration allowed to be null? It might not like the possibility of adding a null value to date Commented Dec 23, 2015 at 15:59
  • Possible duplicate of How to use a string/column value as a mysql date interval constant (DAY, MONTH...)? Commented Dec 23, 2015 at 16:00
  • CREATE TABLE IF NOT EXISTS wp ( user varchar(32) NOT NULL default '', customers_id int(11) NOT NULL, OrderDate datetime NOT NULL, products_id int(11) NOT NULL, PRIMARY KEY (user), UNIQUE KEY customers_id (customers_id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; Commented Dec 23, 2015 at 16:02

1 Answer 1

2

Remove whitespace after DATE_ADD:

SELECT 
wp.customers_id, 
wp.OrderDate, 
wp.products_id,
WPProduct.Duration,
DATE_ADD(wp.OrderDate, INTERVAL WPProduct.Duration DAY) AS ExpiryDate
FROM wp 
INNER JOIN WPProduct ON WPProduct.products_id = wp.products_id
WHERE wp.customers_id = 2
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.