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
user1898525
  • 133
  • 4
  • 14
  • post your tables' schmas – Nir Levy Dec 23 '15 at 15:56
  • Is `WPProduce.Duration` allowed to be null? It might not like the possibility of adding a null value to date – gabe3886 Dec 23 '15 at 15:59
  • Possible duplicate of [How to use a string/column value as a mysql date interval constant (DAY, MONTH...)?](http://stackoverflow.com/questions/888971/how-to-use-a-string-column-value-as-a-mysql-date-interval-constant-day-month) – Atri Dec 23 '15 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; – user1898525 Dec 23 '15 at 16:02

1 Answers1

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
Inpego
  • 2,657
  • 13
  • 14