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
 General SQL Server Forums
 New to SQL Server Programming
 adding a calculation column

Author  Topic 

jkpaco
Starting Member

6 Posts

Posted - 2010-10-19 : 21:39:07
Good evening,

Really hoping someone can help. I appreciate any replies.

I'm tring to calculate the distance between two points, using lat and long. I keep getting a domain error. Should I be adding an if null condition to the below? If so, how can i do this?

alter table testnew3
add math as
1.852 * 60.0 * degrees (Acos(Sin(Radians(lat))
* Sin(Radians(lattwo))
+ Cos(Radians(lat))
* Cos(Radians(lattwo))
* Cos(Radians(longtwo)-Radians(long))))


thank you again for your help.
jk

naveengopinathasari
Yak Posting Veteran

60 Posts

Posted - 2010-10-20 : 01:05:05
alter table testnew3
add lat int ,
lattwo int ,
longtwo int ,
long int ,
math as
1.852 * 60.0 * degrees (Acos(Sin(Radians(lat))
* Sin(Radians(lattwo))
+ Cos(Radians(lat))
* Cos(Radians(lattwo))
* Cos(Radians(longtwo)-Radians(long))))


Change the data type you require for the above set columns

Lets unLearn
Go to Top of Page

jkpaco
Starting Member

6 Posts

Posted - 2010-10-20 : 07:19:42
Thank you!!!!!

I'm going to give it a try today. Appreciate you spending time on this.
Go to Top of Page

jkpaco
Starting Member

6 Posts

Posted - 2010-10-20 : 10:37:18
Hi all,

Are there any other suggestions? I've tried the suggestion above, and it still doesn't work.

thank you,

jk
Go to Top of Page

jkpaco
Starting Member

6 Posts

Posted - 2010-10-20 : 13:04:56
anyone??
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-20 : 13:06:18
what was the error you got?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jkpaco
Starting Member

6 Posts

Posted - 2010-10-20 : 13:09:48
thank you for the response.

the error was:

Msg 3623, Level 16, State 1, Line 2
A domain error occurred.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-20 : 13:14:17
I think thats because its trying to do an illegal mathematical operation. are you sure the formula applied is correct?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

jkpaco
Starting Member

6 Posts

Posted - 2010-10-20 : 13:37:24
I've tested the formula multiple times, with a couple of lines. However, when using a large table of data, I get the error message.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-10-20 : 13:44:07
thats because there're some values in data which when used in formula is causing it to perform illegal mathematical operation. First check expressions used inside functions like cos sin etc to for the data and check if any of them returns invalid values

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-10-20 : 13:47:04
If you are trying to calculate the great circle distance, look at this link:
Great Circle Distance Function - Haversine Formula
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=81360

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -