Convert VB.NET to TSQL PROC & Reference a Proc from another Proc

Convert VB.NET to TSQL PROC & Reference a Proc from another Proc

Post by Truett Woo » Sun, 05 Jun 2005 00:40:48


David,
My math skills are not as good as yours, however, my SQL skills are strong. I played with your logic some, to attempt to help you out, but, when you look at it, you'll probably find my math error right away. You got 15 miles, and I'm getting 18 ... this is probably a rounding error somewhere that you'll be able to find.
I started from your VB code, instead of trying to use the SQL code. I looked at the SQL code and recognized issues, so I started over from the VB Code.
When you find my rounding error, I'd appreciate a response
to ctruett3 at gmail.
hope this was helpful. As to the second portion of the post, try creating a function (Like below) instead of a stored procedure, this will allow you to use it in-line like:
/*
Select Top 1
dbo.fnuFindDistance(41.63, -87.73, 41.7, -88.07) Distance
, name
From
master.dbo.sysobjects
*/

--spuFindDistance 41.63,-87.73,41.7,-88.07
--Your answer = 15.81
Create Procedure
dbo.spuFindDistance
(
@FromLat float
, @FromLong float
, @ToLat float
, @ToLong float
)
As
Declare @Miles float

Select @Miles = Sin(dbo.f *** gToRads(@FromLat))
* Sin(dbo.f *** gToRads(@ToLat))
+ Cos(dbo.f *** gToRads(@FromLat))
* Cos(dbo.f *** gToRads(@ToLat))
* Cos(Abs(dbo.f *** gToRads(@ToLong) - dbo.f *** gToRads(@FromLong)))

Select @Miles = Atan(Sqrt(1 - Power(@Miles, 2)) / @Miles)

Select @Miles = (60.0 * ((@Miles / PI()) * 180) * 1.1507794480235425)

Select @Miles [Distance]
Go


Create Function
dbo.f *** gToRads
(
@Deg float
)
Returns float
As
Begin
Declare @RetVal float

Select @RetVal = Cast(@Deg * Pi() / 180 as float)

Return @RetVal
End
Go


**********************************************************************
Sent via Fuzzy Software @ http://www.yqcomputer.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
 
 

Convert VB.NET to TSQL PROC & Reference a Proc from another Proc

Post by Tim Hea » Tue, 24 Jan 2006 22:02:00


Tim Heap
Software & Database Manager
POSTAR Ltd
www.postar.co.uk
XXXX@XXXXX.COM

*** Sent via Developersdex http://www.yqcomputer.com/ ***