) insert into #a select 'a' union all select 'b' union all select 'c' union all select 'd' union all select 'e' insert into #b select '1','a' union all select '2','b' union all select 'n','c' union all select 'k','d' union all select 'u','e' select a.* ,b.* from #a a ,#b b where cast(b.id as int)=a.id drop table #a drop table #b--(5 行受影响)--(5 行受影响) 消息 245,级别 16,状态 1,第 25 行 在将 nvarchar 值 'n' 转换成数据类型 int 时失败。
建议LZ字段设置时,ID类型设置一样的。
比如:[ID] [int] IDENTITY(1,1) NOT NULL
建议LZ字段设置时,ID类型设置一样的。3楼的,如果b表ID有非数字,会出错误。
CREATE TABLE #a(
[ID] [int] IDENTITY(1,1) NOT NULL,
[tName] [nvarchar](50) NULL
)
CREATE TABLE #b(
[ID] [nvarchar](20) NOT NULL,
[tName] [nvarchar](50) NULL
)
insert into #a
select 'a' union all
select 'b' union all
select 'c' union all
select 'd' union all
select 'e' insert into #b
select '1','a' union all
select '2','b' union all
select 'n','c' union all
select 'k','d' union all
select 'u','e' select a.* ,b.* from #a a ,#b b where cast(b.id as int)=a.id
drop table #a
drop table #b--(5 行受影响)--(5 行受影响)
消息 245,级别 16,状态 1,第 25 行
在将 nvarchar 值 'n' 转换成数据类型 int 时失败。