>select 3, 'Brussels', 50.00 + 50./60. + 0./3600.0, 4.0 + 20.0/60.0 + 0.0/3600.0 >>If I take the dots away as in
select 3, 'Brussels', 50.00 + 50/60 + 0/3600, 4.0 + 20/60 + 0/3600>Then 50.0 and 4.0 get inserted
>declare @City table >( ci_Id int, > ci_desc varchar(60), > ci_latitude float, > ci_longitude float, > ci_x float, > ci_y float, > ci_z float > ) > >insert into @City (ci_Id, ci_desc, ci_latitude, ci_longitude) >select 1, 'Here', 47.77950, -65.7191 >union all >select 2, 'There', 47.5993, -65.6506 >union all >select 3, 'Brussels', 50.00 + 50./60. + 0./3600.0, 4.0 + 20.0/60.0 + 0.0/3600.0 > >update @City > set ci_x = cos(radians(ci_latitude)) * cos(radians(ci_longitude)), > ci_y = cos(radians(ci_latitude)) * sin(radians(ci_longitude)), > ci_z = sin(radians(ci_latitude)) > >select * from @City > >declare @CenterLat float=47.7795 >declare @CenterLon float=-65.7191 >declare @SearchDistance float=250 >declare @EarthRadius float=6371 > >declare @CntXAxis float >declare @CntYAxis float >declare @CntZAxis float > >set @CntXAxis = cos(radians(@CenterLat)) * cos(radians(@CenterLon)) >set @CntYAxis = cos(radians(@CenterLat)) * sin(radians(@CenterLon)) >set @CntZAxis = sin(radians(@CenterLat)) > >-- all distances >select *, > calculatedDistance = @EarthRadius * acos( ci_x*@CntXAxis + ci_y*@CntYAxis + ci_z*@CntZAxis) > from @City > >select test2.* > from ( > select *, > calculatedDistance = @EarthRadius * acos( ci_x*@CntXAxis + ci_y*@CntYAxis + ci_z*@CntZAxis) > from @City > where (ci_latitude between @CenterLat - @SearchDistance/111.0 and @CenterLat + @SearchDistance/111.0) > and (ci_longitude between @CenterLon - @SearchDistance/111.0 and @CenterLon + @SearchDistance/111.0) > ) Test2 > where (calculatedDistance <= @SearchDistance) > > >Thanks, this is all correct. There were issues about the . and the formula. As you might have seen by now, we have resolved all this today. There was a lot of great ideas and documentation provided. I was able to fine tune all this and I am now working in building it all in a class.