int类型的算术溢出错误

时间:2016-08-03 14:22:14

标签: sql sql-server sql-server-2012

我在桌上选择时出现此错误

int类型的算术溢出错误,值= 4318826193.000000。

我试图找出导致此问题的列,使用此值4318826193.000000找出导致此问题的列的最佳方法是什么?

我尝试使用CAST([列名]作为bigint)编写带有所有INT列的select语句,但仍然出现错误。

 SELECT
       CAST(Id AS BIGINT)
      ,CAST (CreatedBy as BIGINT)
      ,CAST (UpdatedBy as BIGINT)
      ,CAST (HeaderId as BIGINT)
      ,CAST (DiskFileId as BIGINT)
      ,CAST (Status as BIGINT)
      ,CAST (TotalLines as BIGINT)
      ,CAST (CompletedLines as BIGINT)
      ,CAST (ProcessedLines as BIGINT)
      ,CAST (PercentComplete as BIGINT)
      ,CAST (SecondsRemaining as BIGINT)
      ,CAST (RollbackUser as BIGINT)
      ,CAST (CreatedRecords as BIGINT)
      ,CAST (UpdatedRecords as BIGINT)
      ,CAST (SkippedRecords as BIGINT)
      ,CAST (DiallerExportProgress as BIGINT)
      ,CAST (idxCampaignId as BIGINT)
      ,CAST (ScheduleId as BIGINT)
      ,CAST (CampaignId as BIGINT)

 from [table_name]

由于

2 个答案:

答案 0 :(得分:2)

使用Try_convert,对于转换失败而不是错误输出,TRY_Convert引发null

select try_convert(int,4318826193.000000)

如何使用..

Select TRY_CONVERT(BIGINT,DiskFileId)

答案 1 :(得分:0)

您可以在所有列上使用max并获取最大值以查找生成它的列。