Sql Server 2000中类型的算术溢出错误。

时间:2022-08-22 22:47:47

In an SQL SERVER 2000 table,there is a column called Kpi of float type. when try to convert that column to varchar(cast(kpi as varchar(3))),It gives an error

在SQL SERVER 2000表中,有一个列称为浮点类型的Kpi。当尝试将该列转换为varchar(cast(kpi为varchar(3))))时,会出现错误

Msg 232, Level 16, State 2, Line 1
Arithmetic overflow error for type varchar, value = 26.100000.

The thing is the column has only one distinct value and that is 26.1. I can not understand why does it show error when converting it into varchar!

这一列只有一个不同的值那就是26。1。我不明白为什么它在转换成varchar时显示错误!

3 个解决方案

#1


2  

your error has triggered by full stop in 26.1.

你的错误是由26.1的完全停止触发的。

you have applied this command:

您已经应用了以下命令:

cast(kpi as varchar(3))

First: change cast from varchar(3) to varchar(4) (to get the first value after full stop)

首先:从varchar(3)转换为varchar(4)(在完全停止后获取第一个值)

So you'll have:

所以你必须:

This line convert value 26.10000000 in 26.1

这条线在26.1中转换为26.1万

Then you apply varchar(26.1) not correct!

那么你申请varchar(26.1)不正确!

Varchar type wants only integer value as size.

Varchar类型只需要整数值作为大小。

Why you apply the last varchar?? I think you must to remove the external varchar and leave only cast function

你为什么要申请最后的varchar??我认为你必须删除外部的varchar和只留下铸造功能

#2


2  

Try this instead:

试试这个:

declare @x float = 26.1
select left(@x,3)

Result will be 26.

结果将是26岁。

#3


1  

The distinct value is 26.1 ,which is 4 character length and the attempt was to cast it to cast(kpi as varchar(3))...If change it to cast(kpi as varchar(4)) it would work and ll get 26.1

不同的值是26.1,即4个字符长度,并尝试将其转换为cast(kpi为varchar(3))…如果将它更改为cast(kpi为varchar(4)),它将正常工作,将得到26.1

#1


2  

your error has triggered by full stop in 26.1.

你的错误是由26.1的完全停止触发的。

you have applied this command:

您已经应用了以下命令:

cast(kpi as varchar(3))

First: change cast from varchar(3) to varchar(4) (to get the first value after full stop)

首先:从varchar(3)转换为varchar(4)(在完全停止后获取第一个值)

So you'll have:

所以你必须:

This line convert value 26.10000000 in 26.1

这条线在26.1中转换为26.1万

Then you apply varchar(26.1) not correct!

那么你申请varchar(26.1)不正确!

Varchar type wants only integer value as size.

Varchar类型只需要整数值作为大小。

Why you apply the last varchar?? I think you must to remove the external varchar and leave only cast function

你为什么要申请最后的varchar??我认为你必须删除外部的varchar和只留下铸造功能

#2


2  

Try this instead:

试试这个:

declare @x float = 26.1
select left(@x,3)

Result will be 26.

结果将是26岁。

#3


1  

The distinct value is 26.1 ,which is 4 character length and the attempt was to cast it to cast(kpi as varchar(3))...If change it to cast(kpi as varchar(4)) it would work and ll get 26.1

不同的值是26.1,即4个字符长度,并尝试将其转换为cast(kpi为varchar(3))…如果将它更改为cast(kpi为varchar(4)),它将正常工作,将得到26.1