Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

The following code works, but it woefully slow:

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

Is there a better way to determine if a GEOGRAPHY value has the Lat/Long of 0,0 ?

like image 791
Pure.Krome Avatar asked Mar 16 '23 10:03

Pure.Krome


2 Answers

Flip yo test, yo. ;)

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

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

Put another way, the query that you originally wrote wasn't SARGable. The one that I wrote is.

like image 106
Ben Thul Avatar answered Mar 19 '23 07:03

Ben Thul


You can use the .Lat and .Long to achieve that. Something like this

SELECT TOP 100 FooId
FROM dbo.Foos
WHERE latitudelongitude.Lat = 0 AND latitudelongitude.Long = 0
ORDER BY FooId desc
like image 28
ughai Avatar answered Mar 19 '23 06:03

ughai