Anyone figured out how to calculate the distance between two sets of LONG/LAT coordinates using SQL?

I have come very close but am still off, using the following query as a user defined function:

CREATE FUNCTION [dbo].[fnCalcDistance]
(
@startLat decimal (11,6),
@startLong decimal (11,6),
@endLat decimal (11,6),
@endLong decimal (11,6)
)
RETURNS INT AS
BEGIN
RETURN ((sqrt(square(abs(cast(@startLat as float) - cast( @endLat as float))) + square(abs(cast(@StartLong as float) - cast(@endLong as float)))) * 3963.1)/ 5700)


END

But my trig (and my borrowed equations) are somewhat weak. Anyone got any ideas?

Edward R. Hunter, MCSE, MSOQ
xinphinity@hotmail.com