使用SQL地理位置获取某个半径的位置

我有一个带有Geography类型的sql表列:
create table dbo.Events
(
  Id int identity not null 
    constraint PK_Events_Id primary key clustered (Id),Localization geography not null
);

我怎样才能获得半径为40公里的所有活动?这可能吗?

谢谢,
米格尔

解决方法

假设您有要搜索的点的纬度和经度:
DECLARE @Origin GEOGRAPHY,-- distance defined in meters
        @distance INTEGER = 40000;        

-- center point
SET @Origin = GEOGRAPHY::STGeomFromText('POINT(-122.084039 37.42227)',4326);

-- return all rows from events in 40km radius
SELECT * FROM dbo.Events WHERE @Origin.Stdistance(Localizaton) <= @distance;

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...