Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm beginner with SQL Server (2012). I created a spatial index, and I'm trying to force SQL Server to use that index to solve the query.

Here's what I have:

DECLARE @g geography

SET @g = geography::STPointFromText('POINT(-79.25161 43.735965)', 4326)

SELECT *

FROM CUSTOMER

WITH(INDEX(idx_Geography))

where HomeGeog.STDistance(@g)

The spatial index (idex_Geography) is created for HomeGeog.

I'm getting this error: Msg 102, Level 15, State 1, Line 5 Incorrect syntax near '('.

I'm not sure where the error is...

Thanks for you help!

share|improve this question

1 Answer 1

The issue is with your use of STDistance rather than the index. This function calculates the distance between two points so you need to replace HomeGeog with a feature rather than the name of the table.

E.g. @g.STDistance(@g) should work (but always return 0)

What are you trying to return from your query?

See http://msdn.microsoft.com/en-us/library/bb933952.aspx for more details on how to use the STDistance function.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.