title: Msg 248, Level 16, State 1, Line 1 The conversion of the varchar value '60811404740101-60811404740102' overflowed an int column
body: <p>I am getting errors with the following stored procedure. I'd like to say that I am new to SQL and currently not up to par yet but anyway, here is the values I'm passing: </p>
  
  <pre><code>USE [AFCache]
  GO
  
  DECLARE @return_value int
  
  EXEC @return_value = [dbo].[csp_WellTestValidationResults_GetData]
                          @ColumnName = N'API14-2',
                          @ColumnValue = N'60811404740101-60811404740102'
  
  SELECT  'Return Value' = @return_value
  GO
  </code></pre>
  
  <p>and here is the actual stored procedure:</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[csp_WellTestValidationResults_GetData]
      -- Declare variables that will get data passed from PIAF to query data
      (@ColumnName varchar(max) = 'Blank',
       @ColumnValue varchar(max) = 'Blank')
  AS
  BEGIN
      SET NOCOUNT ON;
  
      IF (@ColumnName = 'API14-2')
      BEGIN
          DECLARE @APIStrip varchar(max);
          SET @APIStrip = SUBSTRING(@ColumnName, 0, CHARINDEX('-   ', @ColumnName, 0));
  
          DECLARE @LeftNumber varchar(max);
          SET @LeftNumber = SUBSTRING(@ColumnValue, 0, CHARINDEX('-', @ColumnValue, 0));
  
          DECLARE @RightNumber varchar(max)
          SET @RightNumber = SUBSTRING(@ColumnValue, CHARINDEX('-', @ColumnValue, 0) + 1, LEN(@ColumnValue));
  
          EXEC('Select * from dbo.SSIS_RTRM_WellTestValidationResults where '+@APIStrip+' = '+@LeftNumber+' OR '+@APIStrip+' = '+@RightNumber+' order by TestDate Desc') 
      END
  
      IF (@ColumnName = 'API14')
      BEGIN
          EXEC('Select * from dbo.SSIS_RTRM_WellTestValidationResults where '+@ColumnName+' = '''+@ColumnValue+''' order by AssetName, ReservoirName, API14, TestDate Desc')
      END 
  
      IF (@ColumnName &lt;&gt;'AssetName') or (@ColumnName &lt;&gt;'ReservoirName') or   (@ColumnName &lt;&gt;'FieldName') 
      BEGIN
          EXEC('Select wtvv.* from dbo.SSIS_RTRM_WellTestValidationResults wtvv join  '+'(select WellId, Max(TestDate) AS TestDate from dbo.SSIS_RTRM_WellTestValidationResults wtv group by WellId)'+' wtvv1 on wtvv1.WellId = wtvv.WellId and wtvv1.TestDate = wtvv.TestDate where '+@ColumnName+' = '''+@ColumnValue+''' order by AssetName, ReservoirName, API14')
      END
  
      IF (@ColumnName &lt;&gt;'AssetName') or (@ColumnName &lt;&gt;'ReservoirName') or   (@ColumnName&lt;&gt; 'FieldName')or (@ColumnName &lt;&gt;'API14-2')or (@ColumnName &lt;&gt;'API')
      BEGIN
          SELECT * 
          FROM dbo.SSIS_RTRM_WellTestValidationResults 
          WHERE WellId = ''
      END
  END
  </code></pre>
  
  <p>When I execute the query I keep getting the following error: </p>
  
  <blockquote>
    <p>Msg 248, Level 16, State 1, Line 1<br>
    The conversion of the varchar value '60811404740101-60811404740102' overflowed an int column.</p>
  </blockquote>
  
  <p>I have gone through the code and I don’t understand where is my problem and why am I getting this error.</p>