4

I am very new to MS SQL 2008. I got a task to select a polygon from the polygon layer by giving the X-Y coordinates. I already got the script for PostgreSQL for the same thing, but I need it for MS SQL 2008. the code in PostgreSQL is:

SELECT * 
FROM "Kar_bbmp_198" 
WHERE ST_Within 
  ((ST_GeomFromText('POINT(773824 1442012)',32643)), the_geom) = TRUE;` 

Can anybody help me from this?

2
  • Is your data stored in the GEOMETRY or GEOGRAPHY data type? Jul 25, 2012 at 8:40
  • may i know, is any difference will be there if the data stored in Geometry or Geography. Actually i dont know about the storage of data..
    – Kishor
    Jul 25, 2012 at 8:48

2 Answers 2

2

ASPMapper probably has the right approach, but I think you do not want STIntersects (that would imply that the point is on the boundary) or STWithin (which would imply that the polygon is within the point). STContains is probably what you need.

1
SELECT * FROM 
[TABLE_NAME]
WHERE 
[TABLES_SPATIAL_COLUMN].STIntersects(GEOGRAPHY::STGeomFromText('POINT(773824 1442012)',[SRID - e.g. 4326])) = 1

You can change the GEOGRAPHY:: to GEOMETRY:: depending on the data type you are using. Also, you could also use .STWithin(), .STContain() to do this.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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