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.应该怎么转化一下类型呢?

解决方案 »

  1.   

    Select a.ID,b.ID From Table1 as a inner join Table2 as b on cast(a.ID as bigint) = b.ID
      

  2.   

    Select a.ID,b.ID From Table1 as a inner join Table2 as b on cast a.ID = cast(b.ID as varchar)
      

  3.   


    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)
      

  4.   

    declare @t1 table(id bigint)
    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
      

  5.   

    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/*
    id                   id         
    -------------------- ---------- 
    2                    2id                   id         
    -------------------- ---------- 
    2                    2
    */
      

  6.   

    应该不用显示转换吧~
    你Table1的ID字段是不是有非数字的数据
      

  7.   


    select * from Table1 inner join Table2 on Table1.id = Table2.id
    where isnumeric(Table1.id) = 1
      

  8.   

    ]
    '借用楼上'
    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
      

  9.   

    都转成int型,就可以连接了。