ABaut
ABaut

Reputation: 145

How to use STIntersect in SQL SERVER

I want to to perform a STInteract using two tables and finding the intersections of the lines onto a given polygon. I have converted all the tables to have geometries for all. I am having a problem writing the query for this.

These are my two table

  1. HWY_Database = contains the lines
  2. POLY_Database = Polygon of interest

This is my script:

--visually checking if they intersect
SELECT GEOM FROM [dbo].[HWY_Database] where STFIPS = '04'
UNION ALL 
SELECT NEATCELL FROM [dbo].[POLY_Database]

So I dont know how to write this so this what I Initially wrote:

--intersect Neatcell and GEOM
SELECT GEOM FROM [dbo].[HWY_Database] where STFIPS = '04'
Where GEOM.STIntersects(NEATCELL FROM [dbo].[POLY_Database])

Upvotes: 0

Views: 7948

Answers (1)

Ben Thul
Ben Thul

Reputation: 32707

SELECT GEOM 
FROM [dbo].[HWY_Database] as hwy
join [dbo].[POLY_Database] as p
    on hwy.GEOM.STIntersects(p.NEATCELL) = 1
where STFIPS = '04'

Upvotes: 1

Related Questions