将varchar值的转换溢出int列(The conversion of the varchar v

2019-08-17 09:22发布

对于一些价值@nReservationID

SELECT @phoneNumber=
  CASE 
    WHEN  ISNULL(rdg2.nPhoneNumber  ,0) = 0 THEN ISNULL(rdg2.nMobileNumber, 0)
    ELSE ISNULL(rdg2.nPhoneNumber  ,0)
  END 
from tblReservation_Details_Guest  rdg2 
where nReservationID=@nReservationID

为什么会出现这样的错误?

消息248,级别16,状态1,过程USP_CRE_WEB_MEMBER_AUTOGENERATEDECV,136线将varchar值“08041159620”的转化溢出int列。

Answer 1:

Declare @phoneNumber int

select @phoneNumber=Isnull('08041159620',0);

给错误:

The conversion of the varchar value '8041159620' overflowed an int column.: select cast('8041159620' as int)

整数被定义为:

1(2,147,483,647) - 从-2 ^ 31(2,147,483,648)通过2 ^ 31的整数(整数)的数据。 存储大小为4个字节。 在SQL-92同义词int是整数。

Declare @phoneNumber bigint

参考



Answer 2:

由于拉维和其他用户....不过我已经得到了解决

SELECT @phoneNumber=
CASE 
  WHEN  ISNULL(rdg2.nPhoneNumber  ,'0') in ('0','-',NULL)
THEN ISNULL(rdg2.nMobileNumber, '0') 
  WHEN ISNULL(rdg2.nMobileNumber, '0')  in ('0','-',NULL)
THEN '0'
  ELSE ISNULL(rdg2.nPhoneNumber  ,'0')
END 
FROM tblReservation_Details_Guest  rdg2 
WHERE nReservationID=@nReservationID

只需要把“0”,而不是0



文章来源: The conversion of the varchar value overflowed an int column