我正在尝试以下SQL:
update Sales_details set due_date = DATE_ADD(last_sale_date, INTERVAL 35 DAY) where task = 230
并出现以下错误
语法错误:#1064 - 您的SQL语法出错;检查 手册,对应右边的MySQL服务器版本 要在&INTERCAL35DAY)附近使用的语法来自Sales_details WHERE task = 230'在第1行
我已经尝试了以下SQL并且它运行良好:
select last_sale_date, DATE_ADD(last_sale_date, INTERVAL 35 DAY) from Sales_details where task = 230
为什么DATE_ADD
无法在Update
声明中发挥作用?
答案 0 :(得分:0)
适用于mysql !!你的语法错了 - 你在sqlserver中使用了mysql的语法,
请检查ADDDATE for 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>