Can someone clarify for me why I get an error when trying to set the @a variable in the example below?
DECLARE @a BIGINT SET @a = 7*11*13*17*19*23*29*31 /* ERROR: Msg 8115, Level 16, State 2, Line 1 Arithmetic overflow error converting expression to data type int. */
Now I could understand that, internaly, SQL starts to do the math, calculating the multiplication and putting the temporary result in INT, then it passes it to BIGINT.
However, if I add 1.0 * to the list of numbers, there are no errors, so I believe that during this time SQL uses float as a temporary result, and then sends it to BIGINT
DECLARE @b BIGINT SET @b = 1.0 * 7*11*13*17*19*23*29*31 /* NO ERROR */
Honestly, I see nothing wrong with the code ... it's that simple ...
[I am using SQL 2008]
[EDIT]
Thanks to Nathan for the link. This is good information that I didnβt know about, but I still donβt understand why I get the error and why I have βtricksβ to get a simple script of how it works.
Is this what I need to know how to deal with a programmer?
Or, this is a mistake, and if so, I will consider this issue closed.
leoinfo
source share