SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 A domain error occurred in Sql server
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

roshanrise
Starting Member

India
1 Posts

Posted - 04/22/2013 :  09:24:42  Show Profile  Reply with Quote
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

Edited by - roshanrise on 04/22/2013 09:25:33

bandi
Flowing Fount of Yak Knowledge

India
2218 Posts

Posted - 04/22/2013 :  09:42:48  Show Profile  Reply with Quote
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

Edited by - bandi on 04/22/2013 09:51:23
Go to Top of Page

russell
Pyro-ma-ni-yak

USA
5072 Posts

Posted - 04/22/2013 :  14:26:48  Show Profile  Visit russell's Homepage  Reply with Quote
Make sure there are no divide by zero happening too
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000