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
 New to Functions

Author  Topic 

werhardt
Constraint Violating Yak Guru

270 Posts

Posted - 2012-04-16 : 10:43:39
I really don't know that much about functions. My boss has setup a function that I can include in my report, but not sure how to go about doing it.

We need to finde the distance between two zips Member/Facility. I was able to get the long/lat for the member and Facility, but I don't know how to use this function to calculate.

Example.

Member zip 15904, LONG 40.2862 and Lat -78.8662
Facility zip 15201 Long 40.4707 and Lat -79.9543


In my select Statement I declared

@lat1Degrees decimal(15,12),
@lon1Degrees decimal(15,12),
@lat2Degrees decimal(15,12),
@lon2Degrees decimal(15,12)

from the function called [uf_LatLonRadiusDistance], but not sure how to use it in the select statement I am getting blanks.

dbo.[uf_LatLonRadiusDistance](@lat1Degrees,@lon1Degrees,@lat2Degrees,@lon2Degrees)

I probably didn't give you enough detail, let me know. Sorry I am new to this.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-16 : 11:17:48
sounds like it a scalar function. so you can just include it as a column in your select statement.
something like

SELECT dbo.[uf_LatLonRadiusDistance](lat1Degreesfield,lon1Degreesfield,lat2Degreesfield,lon2Degreesfield),...
FROM table


this will calculate distance for each record of table based on row values for lat1Degreesfield,lon1Degreesfield,lat2Degreesfield,lon2Degreesfield fields


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

Go to Top of Page

vinu.vijayan
Posting Yak Master

227 Posts

Posted - 2012-04-17 : 02:48:59
These might help you in the future:

[url]http://www.sqlteam.com/article/user-defined-functions[/url]

[url]http://msdn.microsoft.com/en-us/magazine/cc164062.aspx[/url]

N 28° 33' 11.93148"
E 77° 14' 33.66384"
Go to Top of Page
   

- Advertisement -