类型转换的错误

sinxy 2008-03-31 03:22:04
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.


应该怎么转化一下类型呢?
...全文
90 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hui_hui_2007 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 happyflystone 的回复:]
Select a.ID,b.ID From Table1 as a inner join Table2 as b on cast(a.ID as bigint) = b.ID

[/Quote]
都转成int型,就可以连接了。
wangxuelid 2008-03-31
  • 打赏
  • 举报
回复
]
'借用楼上'
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
viva369 2008-03-31
  • 打赏
  • 举报
回复

select * from Table1 inner join Table2 on Table1.id = Table2.id
where isnumeric(Table1.id) = 1
viva369 2008-03-31
  • 打赏
  • 举报
回复
应该不用显示转换吧~
你Table1的ID字段是不是有非数字的数据
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
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 2

id id
-------------------- ----------
2 2
*/
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
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
dawugui 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用楼主 sinxy 的帖子:]
Table1的ID字段是 nvarchar 类型的
Table2的ID字段是 bigint 类型的

我现在做

SQL codeSelect 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.



应该怎么转化一下类型呢?
[/Quote]

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)
sinxy 2008-03-31
  • 打赏
  • 举报
回复
ls的 我试了一下 还是不行 -_-!
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
Select a.ID,b.ID From Table1 as a inner join Table2 as b on cast a.ID = cast(b.ID as varchar)
-狙击手- 2008-03-31
  • 打赏
  • 举报
回复
Select a.ID,b.ID From Table1 as a inner join Table2 as b on cast(a.ID as bigint) = b.ID

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧