I got this error when trying run my sql query...
我在运行sql查询时出现了这个错误……
Conversion failed when converting the varchar value 'Id' to data type int
在将varchar值“Id”转换为数据类型int时,转换失败。
SELECT *
FROM History
INNER JOIN Header
ON History.Id = Header.docId
Please help me :(
请帮我:(
2 个解决方案
#1
5
In your Join
condition am sure one column is of Integer
type and other one is Varchar
type.
在连接条件中,确保一列是整数类型,另一列是Varchar类型。
ON History.Id = Header.docId
since Int
has higher precedence than varchar
, Varchar
column will be implicitly converted to Int
由于Int的优先级高于varchar,所以varchar列将隐式地转换为Int
So explicitly convert the Int
column to varchar.
因此显式地将Int列转换为varchar。
ON History.Id = cast(Header.docId as varchar(50))
I have considered Header.docId
as Int
type if no, then convert History.Id
to varchar
我认为头。docId为Int类型(如果没有),然后转换历史记录。Id varchar
#2
1
Try casting Id column to INT
尝试将Id列转换为INT
SELECT *
FROM History
INNER JOIN Header
ON cast(History.Id AS int) = Header.docId
#1
5
In your Join
condition am sure one column is of Integer
type and other one is Varchar
type.
在连接条件中,确保一列是整数类型,另一列是Varchar类型。
ON History.Id = Header.docId
since Int
has higher precedence than varchar
, Varchar
column will be implicitly converted to Int
由于Int的优先级高于varchar,所以varchar列将隐式地转换为Int
So explicitly convert the Int
column to varchar.
因此显式地将Int列转换为varchar。
ON History.Id = cast(Header.docId as varchar(50))
I have considered Header.docId
as Int
type if no, then convert History.Id
to varchar
我认为头。docId为Int类型(如果没有),然后转换历史记录。Id varchar
#2
1
Try casting Id column to INT
尝试将Id列转换为INT
SELECT *
FROM History
INNER JOIN Header
ON cast(History.Id AS int) = Header.docId