• 全部
  • 基础类
  • 应用实例
  • 新技术前沿

类型转换的错误

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.


应该怎么转化一下类型呢?
...全文
68 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2008-03-31 03:22
社区公告
暂无公告