i haven't read it, but it looks good
http://msdn.microsoft.com/en-us/libr...8(SQL.90).aspx
took longer to write this post than find it using google
- Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
- Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!
Collapse
You are not logged in or you do not have permission to access this page. This could be due to one of several reasons:
- You are not logged in. If you are already registered, fill in the form below to log in, or follow the "Sign Up" link to register a new account.
- You may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
- If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
Logging in...
Previously on "SQL 2005 – Finding nearest value from a column"
Collapse
-
xyz maps might have something for you:
http://xyzmaps.com/
as well as traditional paper maps, they also supply electronic map data
Leave a comment:
-
I am seeking a list of UK towns with their associated longitude and latitude. I am hoping someone on this thread can suggest a source for such a list.
Ideally I would like to have the following:
town | county | longitude | latitude
Something similar to what is returned by http://freepages.genealogy.rootsweb....ons/index.html
I don't mind paying for such a list but I just cannot find one anywhere.
Leave a comment:
-
Finally got the Lat / Lon bearing working this morning in SQL (well MS SQL 2005)
For those who are intrested here it is - result in whole degrees....
DECLARE @lat1 float
DECLARE @lon1 float
DECLARE @lat2 float
DECLARE @lon2 float
SET @lat1 = 37.286771
SET @lon1 = -97.892715
SET @lat2 = 37.22495
SET @lon2 = -97.95307
DECLARE @y float
DECLARE @x float
DECLARE @dLon float
DECLARE @brng DECIMAL(20,10)
DECLARE @result VARCHAR
SET @lat1 = RADIANS(@lat1)
SET @lat2 = RADIANS(@lat2)
SET @dLon = RADIANS(@lon2 - @lon1)
SET @y = SIN(@dLon) * COS(@lat2)
SET @x = (COS(@lat1) * SIN(@lat2)) - (SIN(@lat1) * COS(@lat2) * COS(@dLon))
SET @brng = (ATN2(@y, @x) * 180) / 3.14159265358979323846
SET @Brng = (@Brng+360) % 360;
SELECT CAST(@brng as INT)
Leave a comment:
-
Originally posted by wxman View Post(not work related!) I am working on a GPS mapping application for use with my hobby.
The GPS produces output in longitude and Latitude – I would then like to run this against a place name table in order to find out the nearest town (I will then go on the work out distance and bearing to this town)
However I am having trouble finding the nearest value in my PlaceName table
[PlaceNames]. [Latitudes]
19.065925
19.107649
19.204109
19.445961
19.449831
If my GPS Latitude is 19.120000 I want to select the second row as the nearest value but if the GPS Latitude is 19.180000 then I want to select the third row.
Any suggestion on the select statement ??
vlookup(19.12,array,2<place name>,true<nearest value>)
Leave a comment:
-
To add to the above.. I need to find the bearing between to points - while i have the JavaScript to do this I am having difficulties converting this to T-SQL - google does not help me here
http://www.movable-type.co.uk/scripts/latlong.htmlLast edited by wxman; 20 June 2008, 21:06.
Leave a comment:
-
I am still working on this ....
Right now I have solved the LAT/LON distance issue on SQL 2005 what I do is first "box" select lat/lons by +-0.5 to each lat/lon to give me a sub set I then run the following function on each lat/lon and order by distance - this all seems to work VERy quickly
CREATE FUNCTION [dbo].[LatLonDistance]
(
@lat1Degrees decimal(15,12),
@lon1Degrees decimal(15,12),
@lat2Degrees decimal(15,12),
@lon2Degrees decimal(15,12)
)
RETURNS decimal(9,4)
AS
BEGIN
DECLARE @earthSphereRadiusNauticalMiles as decimal(10,6)
DECLARE @nauticalMileConversionToMilesFactor as decimal(7,6)
SELECT @earthSphereRadiusNauticalMiles = 6366.707019
SELECT @nauticalMileConversionToMilesFactor = .621371
-- convert degrees to radians
DECLARE @lat1Radians decimal(15,12)
DECLARE @lon1Radians decimal(15,12)
DECLARE @lat2Radians decimal(15,12)
DECLARE @lon2Radians decimal(15,12)
SELECT @lat1Radians = (@lat1Degrees / 180) * PI()
SELECT @lon1Radians = (@lon1Degrees / 180) * PI()
SELECT @lat2Radians = (@lat2Degrees / 180) * PI()
SELECT @lon2Radians = (@lon2Degrees / 180) * PI()
-- formula for distance from [lat1,lon1] to [lat2,lon2]
RETURN ROUND(2 * ASIN(SQRT(POWER(SIN((@lat1Radians - @lat2Radians) / 2) ,2)
+ COS(@lat1Radians) * COS(@lat2Radians) * POWER(SIN((@lon1Radians - @lon2Radians) / 2), 2)))
* (@earthSphereRadiusNauticalMiles * @nauticalMileConversionToMilesFactor), 4)
END
Leave a comment:
-
Originally posted by MrMark View PostAlthough it uses Mysql, this link is good (look at pages 8-13). The sql involved should be very similar
GeoDistance Search
Here's another interesting piece (on a mysql forum)
Mysql Spatial Forum
Leave a comment:
-
Although it uses Mysql, this link is good (look at pages 8-13). The sql involved should be very similar
GeoDistance Search
Here's another interesting piece (on a mysql forum)
Mysql Spatial Forum
Leave a comment:
-
Originally posted by wxman View PostAny suggestion on the select statement ??
2. So you need to calculate the distance, using pythagoras by approximating to a flat surface.
3. So once you've calculated the distance from your location, sort on it.
Select top 1 * from places order by [distance calculation]
4. And then you need to think about how to cope with odd shapes, so you don't conclude that Southend is the closest town to Margate, for example.
Leave a comment:
-
try this
Code:select * into #placenames from ( select 'place1' as place, 19.065925 as latitude union all select 'place2' as place, 19.107649 as latitude union all select 'place3' as place, 19.204109 as latitude union all select 'place4' as place, 19.445961 as latitude union all select 'place5' as place, 19.449831 as latitude ) T1 declare @latitude float --set @latitude = 19.120000 set @latitude = 19.180000 select place, latitude, abs(latitude-@latitude) as diff from #placenames where abs(latitude-@latitude) = (select min(abs(latitude-@latitude)) from #placenames) drop table #placenames
Leave a comment:
-
Surely the row that you want to return would be the row where the (@variablelatitude - row latitude) = min((@variablelatitude - row latitude)), excluding sign. Or something like that.
You can use the ABS function to negate sign
So, something like
SELECT * FROM Table HAVING ABS(@latitude - Table.Latitude) = MIN(ABS(@latitude - Table.Latitude))
Or something like that.
PS - SELECT * FROM Table..... Just for you DP!!!!!Last edited by Weltchy; 19 June 2008, 10:50.
Leave a comment:
-
SQL Server may not be the best for performing spatial database queries.
Have a google, there are other options that specialise in what you want to do.
As per the SQL statement, someone more qualified may be better to answer.
TM
Leave a comment:
-
SQL 2005 – Finding nearest value from a column
(not work related!) I am working on a GPS mapping application for use with my hobby.
The GPS produces output in longitude and Latitude – I would then like to run this against a place name table in order to find out the nearest town (I will then go on the work out distance and bearing to this town)
However I am having trouble finding the nearest value in my PlaceName table
[PlaceNames]. [Latitudes]
19.065925
19.107649
19.204109
19.445961
19.449831
If my GPS Latitude is 19.120000 I want to select the second row as the nearest value but if the GPS Latitude is 19.180000 then I want to select the third row.
Any suggestion on the select statement ??Tags: None
- Home
- News & Features
- First Timers
- IR35 / S660 / BN66
- Employee Benefit Trusts
- Agency Workers Regulations
- MSC Legislation
- Limited Companies
- Dividends
- Umbrella Company
- VAT / Flat Rate VAT
- Job News & Guides
- Money News & Guides
- Guide to Contracts
- Successful Contracting
- Contracting Overseas
- Contractor Calculators
- MVL
- Contractor Expenses
Advertisers
Contractor Services
CUK News
- Streamline Your Retirement with iSIPP: A Solution for Contractor Pensions Sep 1 09:13
- Making the most of pension lump sums: overview for contractors Sep 1 08:36
- Umbrella company tribunal cases are opening up; are your wages subject to unlawful deductions, too? Aug 31 08:38
- Contractors, relabelling 'labour' as 'services' to appear 'fully contracted out' won't dupe IR35 inspectors Aug 31 08:30
- How often does HMRC check tax returns? Aug 30 08:27
- Work-life balance as an IT contractor: 5 top tips from a tech recruiter Aug 30 08:20
- Autumn Statement 2023 tipped to prioritise mental health, in a boost for UK workplaces Aug 29 08:33
- Final reminder for contractors to respond to the umbrella consultation (closing today) Aug 29 08:09
- Top 5 most in demand cyber security contract roles Aug 25 08:38
- Changes to the right to request flexible working are incoming, but how will contractors be affected? Aug 24 08:25
Leave a comment: