Table1的ID字段是 nvarchar 类型的
Table2的ID字段是 bigint 类型的我现在做
Select a.ID,b.ID From Table1 as a inner join Table2 as b on a.ID = b.ID
但是提示类型转化错误:Error converting data type nvarchar to bigint.应该怎么转化一下类型呢?
Table2的ID字段是 bigint 类型的我现在做
Select a.ID,b.ID From Table1 as a inner join Table2 as b on a.ID = b.ID
但是提示类型转化错误:Error converting data type nvarchar to bigint.应该怎么转化一下类型呢?
Select a.ID,b.ID From Table1 as a inner join Table2 as b on cast(a.ID as varchar) = cast(b.ID as varchar)
declare @t2 table(id nvarchar(10))
select *
from @t1 a,@t2 b
where a.id = cast(b.id as bigint)select *
from @t1 a,@t2 b
where cast(a.id as nvarchar) = b.id
declare @t2 table(id nvarchar(10))insert @t1 select 2
insert @t2 select '2'
select *
from @t1 a,@t2 b
where a.id = cast(b.id as bigint)select *
from @t1 a,@t2 b
where cast(a.id as nvarchar) = b.id/*
id id
-------------------- ----------
2 2id id
-------------------- ----------
2 2
*/
你Table1的ID字段是不是有非数字的数据
select * from Table1 inner join Table2 on Table1.id = Table2.id
where isnumeric(Table1.id) = 1
'借用楼上'
declare @t1 table(id bigint)
declare @t2 table(id nvarchar(10))insert @t1 select 2
insert @t2 select '2'
select *
from @t1 a,@t2 b
where a.id = cast(b.id as bigint)select *
from @t1 a,@t2 b
where cast(a.id as nvarchar) = b.id