g33k3dallw33k
g33k3dallw33k

Reputation: 1

Why is POWER(2, 32) throwing an error? SQL

I tried using the SQL POWER Function

SELECT POWER(2, 32)

and it returned this error

Msg 232, Level 16, State 3, Line 21
Arithmetic overflow error for type int, value = 4294967296.000000.

Why does it throw this error and how can I solve it?

Upvotes: 0

Views: 1119

Answers (1)

Thom A
Thom A

Reputation: 95588

The 2 in SELECT POWER(2, 32) is an int, and the largest value an int can store is 2,147,483,647. 4,294,967,296 is too large for that.

Convert your int to a bigint.

SELECT POWER(CONVERT(bigint,2), 32);

From POWER (Transact-SQL) - Return Types:

The return type depends on the input type of float_expression:

Input type                              |Return type
----------------------------------------|--------------
float, real                             |float
decimal(p, s)                           |decimal(38, s)
int, smallint, tinyint                  |int
bigint                                  |bigint
money, smallmoney                       |money
bit, char, nchar, varchar, nvarchar     |float

Upvotes: 5

Related Questions