title: Solving the 'String or binary data would be truncated' error
body: <pre><code>Declare @STAF_TO NVARCHAR(100)
  </code></pre>
  
  <p>I have the following query as part of a SQL Server stored procedure:</p>
  
  <pre><code>SELECT @SF_TO = TP.FRST_NAME + ' ' + TP.MDLE_NAME + ' ' + TP.LAST_NAME
  FROM tbl_Sf TS 
  INNER JOIN tbl_Pl TP ON (TS.POPL_PK = TP.POPL_PK)
  WHERE TS.SF_PK = @ID
  </code></pre>
  
  <p>I know that <code>@ID</code> is equal to 140 (Type <code>INT</code>) based on a print statement that I inserted right before this. When I try to execute this query separately it works fine. </p>
  
  <p>However, when I try to run it as part of the stored procedure I get the following error:</p>
  
  <blockquote>
    <p>Msg 8152, Level 16, State 13, Procedure Proc_Name, Line 57<br>
    String or binary data would be truncated.</p>
  </blockquote>
  
  <p>Line 57 being where the <code>SELECT</code> statement is of the query above. Anyone have any ideas why this could be happening?</p>
  
  <p>EDIT: I tried changing <code>NVARCHAR(100)</code> to <code>NVARCHAR(200)</code> and <code>NVARCHAR(MAX)</code>, still got the error. Also, the query works fine (with 100 characters) if I run it separately.</p>