简体   繁体   English

varchar 值的转换溢出了 sql server 的 int 列

[英]The conversion of the varchar value overflowed an int column with sql server

The conversion of the varchar value '82332617284' overflowed an int column. varchar 值 '82332617284' 的转换溢出了 int 列。

I have data such as我有数据,例如

BreakID = 82332617284

Thus I have line of code to pull out the number only, so it looks like the following:因此,我有一行代码只提取数字,所以它看起来像下面这样:

join dst.ExceptionsDST d on f.BreakOwnerId = replace(substring(d.dstbreakid,charindex('=',d.dstbreakid) + 1,99),' ','')

What do I need to do in order to just pull the numbers and do the join without getting this error?我需要做什么才能只提取数字并进行连接而不会出现此错误?

It is definitely something with this part这绝对是这部分的东西

replace(substring(d.dstbreakid,charindex('=',d.dstbreakid) + 1,99),' ','')

int is too small a datatype for your number. int对于您的数字来说太小了。 You'll have to get rid of so big numbers, or change the column datatype to bigint .您必须摆脱如此大的数字,或将列数据类型更改为bigint

It's clear that your value is bigint.很明显,您的值是 bigint。 Int datatype can't hold it. int 数据类型不能容纳它。

For Example, I'm trying to insert your value #t which is int data type.例如,我试图插入您的值 #t,它是 int 数据类型。 Will end up with same error最终会出现同样的错误

create table #t (id int)
insert into #t values(82332617284)

but this wont error out because it is bigint.但这不会出错,因为它是 bigint。

create table #t1 (id bigint)
insert into #t1 values(82332617284)

So if you can change your code like below will help,因此,如果您可以像下面那样更改代码,将会有所帮助,

join dst.ExceptionsDST d on  f.BreakOwnerId = CAST(replace(substring(d.dstbreakid,charindex('=',d.dstbreakid) + 1,99),' ','') as Bigint)

You can use TRY_CONVERT to avoid this error:您可以使用TRY_CONVERT来避免此错误:

SELECT dstbreakid, TRY_CONVERT(INT, SUBSTRING(d.dstbreakid, CHARINDEX('=', d.dstbreakid) + 1, 99))
FROM (VALUES
    ('x = 82332617284 '),
    ('x = 823326172 ')
) d(dstbreakid)

Output:输出:

| dstbreakid      | (No column name) |
|-----------------|------------------|
| x = 82332617284 | NULL             |
| x = 823326172   | 823326172        |

If f.BreakOwnerId is of datatype int then it cannot contain the value 823326172 .如果f.BreakOwnerId的数据类型为int则它不能包含值823326172

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM