I'm working on my homework and cannot seem to get one of the problems to work properly. I have to create a user defined function that accepts latitude and longitude values for two locations and returns the distance between them. The test values are latitude 3.0664 and longitude 118.3103 for point s and latitude 33.6784 and longitude 118.0054 for point p. If my math is right the distance should come to 1028.280141363536 but when I try to run the function I get 0. The following is the code for the function:CREATE FUNCTION udf_Distance(@distance decimal, @sLat decimal, @pLat decimal,@sLon decimal, @pLon decimal)RETURNS decimalASBEGINSET @distance = SQRT(((69.17 * (@sLat - @pLat)) * (69.17 * (@sLat - @pLat)) + (57.56 * (@sLon - @pLon)) * (57.56 * (@sLon - @pLon))))RETURN @distanceEND
Here is the statement that calls the function:SELECT dbo.udf_Distance (34.0664, 33.6784, 118.3103, 118.0054) AS Distance
Thanks in advance for the help