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.
Author |
Topic |
roshanrise
Starting Member
1 Post |
Posted - 2013-04-22 : 09:24:42
|
I have created a function like the one belowALTER FUNCTION fn_Calc(@Lat1 Float, @Lng1 Float, @Lat2 Float, @Lng2 Float)RETURNS FloatASBEGINDeclare @x as FloatDeclare @y as FloatDeclare @Distance as FloatSelect @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.609344RETURN @DistanceENDI 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. NThanks,Roshan.N |
|
bandi
Master Smack Fu Yak Hacker
2242 Posts |
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2013-04-22 : 14:26:48
|
Make sure there are no divide by zero happening too |
|
|
|
|
|