如何测试 SQL Server Geography 列值是否为 POINT(0 0)?

How to test if a SQL Server Geography column value is POINT(0 0)?

下面的代码可以工作,但是速度太慢了:

select top 100 FooId
from dbo.Foos
where latitudelongitude.ToString() = 'POINT(0,0)'
order by FooId desc

是否有更好的方法来确定 GEOGRAPHY 值是否具有 0,0 的 Lat/Long?

您可以使用 .Lat.Long 来实现。像这样

SELECT TOP 100 FooId
FROM dbo.Foos
WHERE latitudelongitude.Lat = 0 AND latitudelongitude.Long = 0
ORDER BY FooId desc

翻转哟测试,哟。 ;)

declare @g geography = geography::STPointFromText('POINT(0 0)', 4326);

select * 
from dbo.Foos 
where latitudelongitude.STEquals(@g) = 1

换句话说,您最初编写的查询不是 SARGable。我写的那个是。