「車」または「ライン」をどのように表現しているかわからず、仮定を立てる必要があることを考えると、このコード サンプルはボールを転がすことができるかもしれません。どの車がどの線を通過したかを示すデータセットを返します。空間クエリは私の得意分野ではありません。おそらく他の誰かが最適化を提供できるでしょう。
-- This is the first line as describer by 2 points
DECLARE @line1 GEOMETRY = geometry::STGeomFromText('LINESTRING(0 10, 10 10)', 0)
-- This is the second line as describer by another 2 points
DECLARE @line2 GEOMETRY = geometry::STGeomFromText('LINESTRING(0 20, 10 20)', 0)
-- @Car1's path is represented as a line that does NOT intersect the 2 defined lines above
DECLARE @Car1 GEOMETRY = geometry::STGeomFromText('LINESTRING(5 0, 5 11)', 0)
-- @Car2's path is represented as a line that DOES intersect that 2 defined lines above
DECLARE @Car2 GEOMETRY = geometry::STGeomFromText('LINESTRING(5 0, 5 23)', 0)
;WITH Lines (LineID, LineGeom) AS
(
SELECT 1, @line1 UNION ALL
SELECT 2, @line2
)
,Cars (CarID, CarGeom) AS
(
SELECT 1, @Car1 UNION ALL
SELECT 2, @Car2
)
SELECT C.CarID
,L.LineID
FROM Cars C
JOIN Lines L ON L.LineGeom.STIntersects(C.CarGeom) = 1