sql – Unioned select statements cause an int overflow error
I am trying to run this unioned select statement and I’m getting an int overflow error.
The first select has an ID which is an integer so I’ve cast it as a varchar(25).
This levels the playing field, or so I thought, because the ID values in the subsequent two selects with a maximum size of varchar(25).
This is the error.
The conversion of the varchar value ‘24546133202216601’ overflowed an int column
This might be a duplicate, but I couldn’t find an identical question, so is there a way around this?
SELECT CAST(ID AS varchar(25)) AS thisID FROM tblA
UNION
SELECT ID AS thisID FROM tblB
UNION
SELECT ID AS thisID FROM tblC
Read more here: Source link