3

我正在处理从一个数据库到另一个数据库的数据迁移。

到目前为止,一切正常,但在一张桌子上我总是遇到同样的错误。我也想在这个表中迁移的外键有问题。我想我必须为外键声明一些特殊的东西?

这是我的查询:

INSERT INTO [asd].HolidayTracker.dbo.AnnualVacation(UserId,WorkingTime,VacationDays,FromDate,ToDate)
SELECT u1.user_htUserId,
       u1.vacationDays,
       u1.workingTime,
       CAST('2013-01-01' AS DATETIME),
       CAST('2013-12-31' AS DATETIME)

FROM    HolidayTracker.dbo.AnnualVacation u1 
            LEFT JOIN  [asd].HolidayTracker.dbo.AnnualVacation u2
                ON u1.user_htUserId = u2.UserId AND 
                   u1.vacationDays = u2.VacationDays AND
                   u1.workingTime = u2.WorkingTime

这是我收到的错误消息:

error message INSERT INTO [asd].HolidayTracker.dbo.AnnualVacation(UserId,WorkingTime,VacationDays‌​,FromDate,ToDate) – `

这是表结构:源表

在此处输入图像描述

目标表

在此处输入图像描述

4

1 回答 1

0

对于初学者,与您选择的字段相比,插入语句中的 WorkingTime、VacationDays 字段的方式错误。

尝试更改字段的顺序,如下所示,看看会发生什么。

错误可能很简单,就像您尝试将浮点数插入 int 列而不转换值一样。

INSERT INTO [asd].HolidayTracker.dbo.AnnualVacation(UserId,VacationDays,WorkingTime,FromDate,ToDate)
SELECT u1.user_htUserId,
   u1.vacationDays,
   u1.workingTime,
   CAST('2013-01-01' AS DATETIME),
   CAST('2013-12-31' AS DATETIME)

FROM    HolidayTracker.dbo.AnnualVacation u1 
        LEFT JOIN  [asd].HolidayTracker.dbo.AnnualVacation u2
            ON u1.user_htUserId = u2.UserId AND 
               u1.vacationDays = u2.VacationDays AND
               u1.workingTime = u2.WorkingTime
于 2013-04-02T13:42:49.590 回答