2015-09-22 46 views
0

我想下面的SQL:DATE_ADD功能不會更新工作

update Sales_details set due_date = DATE_ADD(last_sale_date, INTERVAL 35 DAY) where task = 230 

,並得到了以下錯誤

syntax 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 'INTERVAL35DAY) FROM Sales_details WHERE task = 230' at line 1

我試過下面的SQL和它的正常工作:

select last_sale_date, DATE_ADD(last_sale_date, INTERVAL 35 DAY) from Sales_details where task = 230 

爲什麼DATE_ADD不起作用Update聲明?

回答

0

適用於mysql!你的語法錯誤車道您使用的是SQLSERVER的MySQL的句法,

請檢查ADDDATE的語法SQLSERVER

SQL Server DATEADD() Function 
DATEADD(datepart,number,date) 


MySQL DATE_ADD() Function 
DATE_ADD(date,INTERVAL expr type) 


mysql> select first_name,birth_date from students where first_name = 'Dale'; 
+------------+------------+ 
| first_name | birth_date | 
+------------+------------+ 
| Dale  | 1959-03-29 | 
+------------+------------+ 
1 row in set (0.00 sec) 

mysql> update students set birth_date = DATE_ADD(birth_date,interval 35 DAY) where first_name = 'Dale'; 
Query OK, 1 row affected (0.00 sec) 
Rows matched: 1 Changed: 1 Warnings: 0 

mysql> select first_name,birth_date from students where first_name = 'Dale'; +------------+------------+ 
| first_name | birth_date | 
+------------+------------+ 
| Dale  | 1959-05-03 | 
+------------+------------+ 
1 row in set (0.00 sec) 

mysql> 
+0

這是MySQL服務器:服務器:通過UNIX套接字 服務器輸入localhost:Percona的服務器 服務器版本:5.5.42-37.1 - Percona服務器(GPL),版本37.1,修訂版本727 協議版本:10 服務器字符集:UTF-8 Unicode(utf8) 爲什麼DATE_ADD在SELECT語句中工作,但沒有UPDATE? – Sbaben