SQL Server: Arithmetic overflow error converting expression to data type bigint

Viewed 55139

Here's the sequence of my query:

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
...

When I run it, I've got the following message:

Arithmetic overflow error converting expression to data type bigint.

The column BarCode is of type bigint, and column ExternelBarCode is of type varchar(250).

BarCode = 178625624324,
ExternelBarCode = 2015591149641227565492

How can I resolve this issue?

1 Answers
Related