sql server - SQL Geography Latitude/Longitude distance calc -


i have trouble using geography calculate distance in miles using format of table.

latitude , longitude of both locations side side:

id | a_latitude | a_longitude | b_latitude | b_longitude 

i'm trying point of a, along point of b, , return distance between a , b in miles.

i've tried few things, including similar to:

declare @orig geography  declare @end geography select @orig = geography::point(a_latitude, a_longitude, 4326)  ,@end = geography::point(b_latitude, b_longitude, 4326)  table1 select      round(@end.stdistance(@orig)/1609.344,2) miles     ,@end.stdistance(@orig) meters     ,table1.* table1; 

where i'm getting repeating value miles , meters across rows. please suggest how should structuring query i'm looking for?

edit: sql surfer!

with x  (select   geography::point(a_latitude, a_longitude, 4326) ,geography::point(b_latitude, b_longitude, 4326) b ,id table1)  select  round(x.b.stdistance(x.a)/1609.344,2) miles ,x.b.stdistance(x.a) meters ,t.* table1 t left join x on t.id = x.id 

here's i'd do:

with x  (    select        geography::point(a_latitude, a_longitude, 4326)      ,geography::point(b_latitude, b_longitude, 4326) b      ,*    table1 )  select     round(b.stdistance(a)/1609.344, 2) miles    ,b.stdistance(x.a) meters    ,* x 

if you're thinking of doing (and on fly), consider adding computed columns table not geography types, distance between them. @ point, it's simple query table!


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -