我正在尝试将数据从一个SQL表插入另一个SQL表。问题是列具有不同的数据类型。当我使用Cast()时,我仍然收到以下错误消息:
[Msg 8114,Level 16,State 5,Line 3将数据类型varchar转换为bigint时出错。]
Table1列的数据类型为bigint或int,而Table2列为varchar。有什么建议吗?
这是我的问题:
INSERT INTO Table1
([RowId],
[Scenario],
[Entity],
[Project],
[TimePeriod])
SELECT Cast([ProjectMgrID] as bigint), Cast('ACT' as bigint),
Cast('APP' as bigint), Cast([Project] as bigint), Cast('201801' as int)
FROM Table2
答案 0 :(得分:0)
使用此
INSERT INTO Table1
([RowId],
[Scenario],
[Entity],
[Project],
[TimePeriod])
SELECT Cast([ProjectMgrID] as bigint), Cast([ACT] as bigint),
Cast([APP] as bigint), Cast([Project] as bigint), Cast('201801' as int)
FROM Table2
您要将字符串转换为bigint Cast('ACT' as bigint),
Cast('APP' as bigint)
,您应该在[]