Is there a way (aside from casting i to something like a bigint) to avoid the arithmetic overflow error in the following set of statements?
DECLARE @tbl TABLE ( [i] INT );
INSERT INTO @tbl
( [i] )
VALUES ( POWER(2, 30) ),
( POWER(2, 30) );
SELECT SUM([t].[i])
FROM @tbl AS [t];
I tried a TRY_CAST() on the SUM() but it seems that the error is happening before that point. I'm fine if a NULL (or any other value) gets returned on an overflow.