title: SQL Server: Arithmetic overflow error converting expression to data type bigint
body: <p>Here's the sequence of my query:</p>
  
  <pre><code>SELECT
        CASE
           WHEN ((BarCode IS NOT NULL) AND (ExternelBarCode IS NULL)) THEN BarCode
           WHEN ((BarCode IS NULL) AND (ExternelBarCode IS NOT NULL)) THEN CAST(ExternelBarCode AS bigint)
           ELSE ExternelBarCode -- When both exist
        END AS TicketBarCode
  ...
  </code></pre>
  
  <p>When I run it, I've got the following message:</p>
  
  <blockquote>
    <p>Arithmetic overflow error converting expression to data type bigint.</p>
  </blockquote>
  
  <p>The column <code>BarCode</code> is of type <code>bigint</code>, and column <code>ExternelBarCode</code> is of type <code>varchar(250)</code>.</p>
  
  <pre><code>BarCode = 178625624324,
  ExternelBarCode = 2015591149641227565492
  </code></pre>
  
  <p>How can I resolve this issue?</p>