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)
 A domain error occurred in Sql server

Author  Topic 

roshanrise
Starting Member

1 Post

Posted - 2013-04-22 : 09:24:42
I have created a function like the one below

ALTER FUNCTION fn_Calc
(@Lat1 Float,
@Lng1 Float,
@Lat2 Float,
@Lng2 Float)
RETURNS Float
AS
BEGIN

Declare @x as Float
Declare @y as Float
Declare @Distance as Float

Select @x = (SIN(RADIANS(@Lat1)) * SIN(RADIANS(@Lat2)) + COS(RADIANS(@Lat1)) * COS(RADIANS(@Lat2)) * COS(ABS((RADIANS(@Lng2)) - (RADIANS(@Lng1)))))
Select @y = ATAN((SQRT(1-(POWER(@x,2))) / @x))

Select @Distance = (1.852 * 60.0 * ((@y / PI()) * 180)) / 1.609344

RETURN @Distance

END

I am using the above function to update a column in a table like below:

Update test set calc = dbo.fn_Calc( cast(Lat as float), cast(Long as float), dblLat, dblLong)

While running the above query I got the error.

"A domain error occured."

What can be causing this error?

Thanks,
Roshan. N

Thanks,
Roshan.N

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-22 : 09:42:48
Check this link http://books.google.co.in/books?id=bTIq5XpJgTkC&pg=PA106&lpg=PA106&dq=%22A+domain+error+occurred.%22+in+sql+server&source=bl&ots=d1WfCcx8DQ&sig=gARctqqHx6V1ywHaaBhNIsS0SVg&hl=en&sa=X&ei=fz11UdqWLsTorQew5IGICA&ved=0CIgBEOgBMAk#v=onepage&q=%22A%20domain%20error%20occurred.%22%20in%20sql%20server&f=false

Some trigonometric or LOG functions can throw domain error in the case of NULL values...
http://stackoverflow.com/questions/1564405/how-to-fix-domain-error-in-sql-server-2005-when-using-log-function-to-get-pr

--
Chandu
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2013-04-22 : 14:26:48
Make sure there are no divide by zero happening too
Go to Top of Page
   

- Advertisement -