Inner Join Returning No Results MS SQL Server -
i have 2 tables containing geographical data.
want inner join table1 table2 of table1 field table2.
when tried following:
select a.*, b.field table1 inner join table2 b on (cast(a.latitude float) = cast(b.latitude float)) , (cast(a.longitude float) = cast(b.longitude float))
i met no results, have checked there same exact pairs of lat longs in both tables.
as check, joined latitudes, longitudes , had results, seems problem having both latitudes , longitudes joined.
joining on floating point numbers wrong thing do. nice if sql parse returned warning when 1 attempts this. problem floating point numbers can same, different in last bit.
first, try using native types (which should decimal or character):
select a.*, b.field table1 inner join table2 b on a.latitude = b.latitude , a.longitude = b.longitude ;
if doesn't work, can use logic this:
select a.*, b.field table1 inner join table2 b on a.latitude between b.latitude - 0.0001 , b.latitude + 0.0001 , a.longitude between b.longitude - 0.0001 , b.longitude + 0.0001;
the 0.0001
arbitrary threshold identifying values being same when different. i'm not sure right value is. however, corresponds 36 feet (11 meters) @ most, seems reasonable precision.
the moral of story lats , longs should stored using fixed-length decimal precision or using representations in gis packages.
Comments
Post a Comment