[英]SQL Server: date incompatible with int when migrating from mysql. How to solve?
I have similar databases, they come from the same CMS but they use different databases: some are originally SQL Server, and another one is MySQL. 我有类似的数据库,它们来自同一CMS,但它们使用不同的数据库:有些数据库最初是SQL Server,另一数据库是MySQL。
I had to migrate the MySQL database to SQL server since I have some scripts ready for SQL Server which a. 我必须将MySQL数据库迁移到SQL Server,因为我已经为SQL Server准备了一些脚本。 a don't want to convert, b. a不想转换b。 are more complicated to convert since some functions I use are not implemented in MySQL. 由于我使用的某些功能未在MySQL中实现,因此转换起来更加复杂。
This query on the database which were originally SQL Server runs without problems: 最初是SQL Server的数据库查询没有问题:
SELECT Birth_Date+1 FROM TABLENAME
while, when I run it on the same table in the database I migrated from SQL, I get this error: 同时,当我在从SQL迁移的数据库中的同一表上运行它时,出现以下错误:
Operand type clash: date is incompatible with int 操作数类型冲突:日期与int不兼容
Any idea why I get this error and how I can solve it? 知道为什么我会收到此错误以及如何解决它吗?
I migrated my database with SSMA, SQL Server Migration Assistent, if this can help. 我可以使用SSMA(SQL Server迁移助手)迁移数据库,如果可以的话。
Thank you. 谢谢。
The message is rather clear, you can't use the +
operator with a date and an int. 该消息非常清楚,您不能将+
运算符与日期和int一起使用。
You should use the DATEADD
function (in Sql Server) 您应该使用DATEADD
函数(在SQL Server中)
And DATE_ADD
in mysql. 和DATE_ADD
在mysql中。
DATE_ADD(Birth_Date, interval 1 DAY)
for example. DATE_ADD(Birth_Date, interval 1 DAY)
。
which is 这是
DATEADD(day, 1, Birth_Date)
in Sql Server SQL Server中的DATEADD(day, 1, Birth_Date)
The error seems pretty clear. 该错误似乎很明显。 You can't add an integer to a date
, although you can add an integer to a datetime
. 尽管可以将整数添加到date
,但不能将整数添加到datetime
。 Presumably, the data type of Birth_Date
is date
in one database and datetime
(or something similar) in the other. 据推测, Birth_Date
的数据类型是一个数据库中的date
和另一个数据库中的datetime
(或类似的datetime
)。
Here are two solutions: 这是两个解决方案:
SELECT cast(Birth_Date as datetime)+1 FROM TABLENAME;
SELECT dateadd(day, 1, Birth_Date) FROM TABLENAME;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.