Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 power function and arithmetic overflow

Author  Topic 

jdawginthecrib
Starting Member

1 Post

Posted - 2012-03-17 : 14:12:15
On my local copy of a database, the code below sometimes generates an arithmetic overflow error and very occasionally generates a domain error. When I run the same code on a server, it never generates an error. I am completely perplexed.

In the code below, I create the table to be used in the join and then have a loop to repeat the join a large number of times.



create table x(a smallint)
declare @a smallint
set @a = 1990

while @a <= 2012
begin

insert into x
select @a as a
set @a=@a+1

end


declare @i int
set @i = 0

while @i < 200000
begin

select

0.0 + cast(power(cast(0.7000000 as float), abs(y.a- b.a)) as decimal(10, 7)) as w

into #x
from x y
inner join x b on b.a between y.a - 4 and y.a + 4

drop table #x

print(@i)
set @i = @i+1

end

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-03-17 : 16:24:38
Maybe it's a bug in SQL? Show us @@VERSION for both.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -