SQL 服务器如何查找几何数据是否在另一个几何数据中?

SQL Server how to find if geometry data is within another geometry data?

我有 2 个 table 包含几何数据的数据。我试图找出来自 HOarea table 的几何数据是否在来自 grid1600 的另一个几何数据中。下面是我的 tables 和一些示例数据:

HO面积table

CREATE TABLE [dbo].[HOarea](
    [HOarea] [nvarchar](255) NULL,
    [GEOM] [nvarchar](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXIa      ', N'0x560D0000010505000000CDCCCCCCCCE2AE40A4703D0AC7F5D740CDCCCCCCCCE2AE40A4703D0AC7DCD740CDCCCCCCCCEEAC40A4703D0AC7DCD740CDCCCCCCCCEEAC40A4703D0AC7F5D740CDCCCCCCCCE2AE40A4703D0AC7F5D740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXa       ', N'0x560D0000010505000000CDCCCCCCCCE2AE40A4703D0AC7DCD740666666666601B140A4703D0AC7DCD740666666666601B140A4703D0AC7F5D740CDCCCCCCCCE2AE40A4703D0AC7F5D740CDCCCCCCCCE2AE40A4703D0AC7DCD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXb       ', N'0x560D0000010505000000666666666601B14066666666869AD740CDCCCCCCCCE2AE4066666666869AD740CDCCCCCCCCE2AE40A4703D0AC7DCD740666666666601B140A4703D0AC7DCD740666666666601B14066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXIb      ', N'0x560D0000010505000000CDCCCCCCCCEEAC40A4703D0AC7DCD740CDCCCCCCCCE2AE40A4703D0AC7DCD740CDCCCCCCCCE2AE4066666666869AD740CDCCCCCCCCEEAC40A4703D0A879AD740CDCCCCCCCCEEAC40A4703D0AC7DCD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXIc      ', N'0x560D0000010505000000CDCCCCCCCCEEAC40A4703D0A879AD740CDCCCCCCCCE2AE4066666666869AD740CDCCCCCCCCE2AE4066666666067AD740CDCCCCCCCCEEAC40A4703D0A077AD740CDCCCCCCCCEEAC40A4703D0A879AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXc       ', N'0x560D0000010505000000CDCCCCCCCCE2AE4066666666869AD740666666666601B14066666666869AD740666666666601B14066666666067AD740CDCCCCCCCCE2AE4066666666067AD740CDCCCCCCCCE2AE4066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XVIc      ', N'0x560D0000010505000000666666666601B14066666666067AD740666666666671B140A4703D0A077AD740666666666671B140A4703D0A8759D740666666666601B140A4703D0A8759D740666666666601B14066666666067AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'lc        ', N'0x560D0000010505000000666666666601B14066666666869AD740666666666671B14066666666869AD740666666666671B140A4703D0A077AD740666666666601B14066666666067AD740666666666601B14066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XVla      ', N'0x560D0000010505000000666666666671B140A4703D0A077AD7406666666666A5B240A4703D0A077AD7406666666666A5B240A4703D0A8759D740666666666671B140A4703D0A8759D740666666666671B140A4703D0A077AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'Ia        ', N'0x560D00000105060000006666666666A5B240EC51B81EC5F5D7406666666666A5B24066666666869AD740666666666671B14066666666869AD740666666666601B14066666666869AD740666666666601B140A4703D0AC7F5D7406666666666A5B240EC51B81EC5F5D740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'Ila       ', N'0x560D00000105050000006666666666A5B24066666666869AD740666666666635B44066666666869AD740666666666635B4404C378941C8F5D7406666666666A5B240B4C876BEC7F5D7406666666666A5B24066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'IIIa      ', N'0x560D0000010505000000666666666635B44066666666869AD7406666666666C5B54066666666869AD7406666666666C5B540105839B4C8F5D740666666666635B4404C378941C8F5D740666666666635B44066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003')

grid1600 table

CREATE TABLE [dbo].[grid1600](
    [grid1600] [int] NULL,
    [GEOM] [nvarchar](max) NULL,
    [HOarea] [nvarchar](255) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (662, N'0x560D00000105050000005E8DF893669DB5403333333363E1D7405E8DF893669DB5403333333343D7D7405E8DF8936675B5403333333343D7D7405E8DF8936675B5403333333363E1D7405E8DF893669DB5403333333363E1D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (663, N'0x560D00000105050000005E8DF893669DB5403333333343D7D7405E8DF893669DB5403333333323CDD7405E8DF8936675B5403333333323CDD7405E8DF8936675B5403333333343D7D7405E8DF893669DB5403333333343D7D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (664, N'0x560D00000105050000005E8DF893669DB5403333333323CDD7405E8DF893669DB5403333333303C3D7405E8DF8936675B5403333333303C3D7405E8DF8936675B5403333333323CDD7405E8DF893669DB5403333333323CDD7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (665, N'0x560D00000105050000005E8DF89366C5B5403333333323CDD7405E8DF89366C5B5403333333303C3D7405E8DF893669DB5403333333303C3D7405E8DF893669DB5403333333323CDD7405E8DF89366C5B5403333333323CDD7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (666, N'0x560D00000105050000005E8DF89366C5B5403333333303C3D7405E8DF89366C5B54033333333E3B8D7405E8DF893669DB54033333333E3B8D7405E8DF893669DB5403333333303C3D7405E8DF89366C5B5403333333303C3D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (667, N'0x560D00000105050000005E8DF89366C5B54033333333E3B8D7405E8DF89366C5B54032A87877C3AED7405E8DF893669DB540DA269978C3AED7405E8DF893669DB54033333333E3B8D7405E8DF89366C5B54033333333E3B8D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (668, N'0x560D00000105050000005E8DF89366C5B54032A87877C3AED7405E8DF89366C5B54033333333A3A4D7405E8DF893669DB54033333333A3A4D7405E8DF893669DB540DA269978C3AED7405E8DF89366C5B54032A87877C3AED7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (669, N'0x560D00000105050000005E8DF89366EDB5408B295876C3AED7405E8DF89366EDB54033333333A3A4D7405E8DF89366C5B54033333333A3A4D7405E8DF89366C5B54032A87877C3AED7405E8DF89366EDB5408B295876C3AED7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (670, N'0x560D00000105050000005E8DF89366C5B5403333333383EBD7405E8DF89366C5B5403333333363E1D7405E8DF893669DB5403333333363E1D7405E8DF893669DB5403333333383EBD7405E8DF89366C5B5403333333383EBD7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (671, N'0x560D00000105050000005E8DF89366C5B5403333333363E1D7405E8DF89366C5B5403333333343D7D7405E8DF893669DB5403333333343D7D7405E8DF893669DB5403333333363E1D7405E8DF89366C5B5403333333363E1D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (672, N'0x560D00000105050000005E8DF89366C5B5403333333343D7D7405E8DF89366C5B5403333333323CDD7405E8DF893669DB5403333333323CDD7405E8DF893669DB5403333333343D7D7405E8DF89366C5B5403333333343D7D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (673, N'0x560D00000105050000005E8DF8936685B4403333333323CDD7405E8DF8936685B4403333333303C3D7405E8DF893665DB4403333333303C3D7405E8DF893665DB4403333333323CDD7405E8DF8936685B4403333333323CDD7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (674, N'0x560D00000105050000005E8DF8936685B4403333333303C3D7405E8DF8936685B44033333333E3B8D7405E8DF893665DB44033333333E3B8D7405E8DF893665DB4403333333303C3D7405E8DF8936685B4403333333303C3D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (675, N'0x560D00000105050000005E8DF8936685B44033333333E3B8D7405E8DF8936685B4406D9D7C80C3AED7405E8DF893665DB440141C9D81C3AED7405E8DF893665DB44033333333E3B8D7405E8DF8936685B44033333333E3B8D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (676, N'0x560D00000105050000005E8DF8936685B4406D9D7C80C3AED7405E8DF8936685B44033333333A3A4D7405E8DF893665DB44033333333A3A4D7405E8DF893665DB440141C9D81C3AED7405E8DF8936685B4406D9D7C80C3AED7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (677, N'0x560D00000105050000005E8DF89366ADB440C51E5C7FC3AED7405E8DF89366ADB44033333333A3A4D7405E8DF8936685B44033333333A3A4D7405E8DF8936685B4406D9D7C80C3AED7405E8DF89366ADB440C51E5C7FC3AED7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (678, N'0x560D00000105050000005E8DF8936685B4403333333383EBD7405E8DF8936685B4403333333363E1D7405E8DF893665DB4403333333363E1D7405E8DF893665DB4403333333383EBD7405E8DF8936685B4403333333383EBD7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (679, N'0x560D00000105050000005E8DF8936685B4403333333363E1D7405E8DF8936685B4403333333343D7D7405E8DF893665DB4403333333343D7D7405E8DF893665DB4403333333363E1D7405E8DF8936685B4403333333363E1D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (680, N'0x560D00000105050000005E8DF8936685B4403333333343D7D7405E8DF8936685B4403333333323CDD7405E8DF893665DB4403333333323CDD7405E8DF893665DB4403333333343D7D7405E8DF8936685B4403333333343D7D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (681, N'0x560D00000105050000005E8DF89366ADB4403333333343D7D7405E8DF89366ADB4403333333323CDD7405E8DF8936685B4403333333323CDD7405E8DF8936685B4403333333343D7D7405E8DF89366ADB4403333333343D7D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (682, N'0x560D00000105050000005E8DF89366ADB4403333333323CDD7405E8DF89366ADB4403333333303C3D7405E8DF8936685B4403333333303C3D7405E8DF8936685B4403333333323CDD7405E8DF89366ADB4403333333323CDD7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (683, N'0x560D00000105050000005E8DF89366ADB4403333333303C3D7405E8DF89366ADB44033333333E3B8D7405E8DF8936685B44033333333E3B8D7405E8DF8936685B4403333333303C3D7405E8DF89366ADB4403333333303C3D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (684, N'0x560D00000105050000005E8DF89366ADB44033333333E3B8D7405E8DF89366ADB440C51E5C7FC3AED7405E8DF8936685B4406D9D7C80C3AED7405E8DF8936685B44033333333E3B8D7405E8DF89366ADB44033333333E3B8D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (685, N'0x560D00000105050000005E8DF89366D5B44033333333E3B8D7405E8DF89366D5B4401EA03B7EC3AED7405E8DF89366ADB440C51E5C7FC3AED7405E8DF89366ADB44033333333E3B8D7405E8DF89366D5B44033333333E3B8D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (686, N'0x560D00000105050000005E8DF89366D5B4401EA03B7EC3AED7405E8DF89366D5B44033333333A3A4D7405E8DF89366ADB44033333333A3A4D7405E8DF89366ADB440C51E5C7FC3AED7405E8DF89366D5B4401EA03B7EC3AED7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (687, N'0x560D00000105050000005E8DF89366ADB4403333333383EBD7405E8DF89366ADB4403333333363E1D7405E8DF8936685B4403333333363E1D7405E8DF8936685B4403333333383EBD7405E8DF89366ADB4403333333383EBD7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (688, N'0x560D00000105050000005E8DF89366ADB4403333333363E1D7405E8DF89366ADB4403333333343D7D7405E8DF8936685B4403333333343D7D7405E8DF8936685B4403333333363E1D7405E8DF89366ADB4403333333363E1D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (689, N'0x560D00000105050000005E8DF89366D5B4403333333363E1D7405E8DF89366D5B4403333333343D7D7405E8DF89366ADB4403333333343D7D7405E8DF89366ADB4403333333363E1D7405E8DF89366D5B4403333333363E1D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (690, N'0x560D00000105050000005E8DF89366D5B4403333333343D7D7405E8DF89366D5B4403333333323CDD7405E8DF89366ADB4403333333323CDD7405E8DF89366ADB4403333333343D7D7405E8DF89366D5B4403333333343D7D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (691, N'0x560D00000105050000005E8DF89366D5B4403333333323CDD7405E8DF89366D5B4403333333303C3D7405E8DF89366ADB4403333333303C3D7405E8DF89366ADB4403333333323CDD7405E8DF89366D5B4403333333323CDD7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (692, N'0x560D00000105050000005E8DF89366D5B4403333333303C3D7405E8DF89366D5B44033333333E3B8D7405E8DF89366ADB44033333333E3B8D7405E8DF89366ADB4403333333303C3D7405E8DF89366D5B4403333333303C3D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003', N'NULL')

我使用了这个查询

SELECT [grid1600] FROM [geo].[dbo].[grid1600] a JOIN [geo].[dbo].[HOarea] b ON a.grid1600 = 662 AND STWITHIN(a.GEOM, b.GEOM)

但我不断收到此错误消息 “消息 195,级别 15,状态 10,第 7 行 'STWITHIN' 不是可识别的内置函数名称。"

有人能帮忙吗?

您应该使用 .STWithin ( other_geometry ),而不是 STWITHIN()。我不确定您的示例数据(GEOM 列数据类型和值)的正确性如何,但下一个示例可能有助于获得有效的解决方案。

Table:

CREATE TABLE [dbo].[HOarea](
    [HOarea] [nvarchar](255) NULL,
    [GEOM] geometry NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXIa      ', 0x560D0000010505000000CDCCCCCCCCE2AE40A4703D0AC7F5D740CDCCCCCCCCE2AE40A4703D0AC7DCD740CDCCCCCCCCEEAC40A4703D0AC7DCD740CDCCCCCCCCEEAC40A4703D0AC7F5D740CDCCCCCCCCE2AE40A4703D0AC7F5D740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXa       ', 0x560D0000010505000000CDCCCCCCCCE2AE40A4703D0AC7DCD740666666666601B140A4703D0AC7DCD740666666666601B140A4703D0AC7F5D740CDCCCCCCCCE2AE40A4703D0AC7F5D740CDCCCCCCCCE2AE40A4703D0AC7DCD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXb       ', 0x560D0000010505000000666666666601B14066666666869AD740CDCCCCCCCCE2AE4066666666869AD740CDCCCCCCCCE2AE40A4703D0AC7DCD740666666666601B140A4703D0AC7DCD740666666666601B14066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXIb      ', 0x560D0000010505000000CDCCCCCCCCEEAC40A4703D0AC7DCD740CDCCCCCCCCE2AE40A4703D0AC7DCD740CDCCCCCCCCE2AE4066666666869AD740CDCCCCCCCCEEAC40A4703D0A879AD740CDCCCCCCCCEEAC40A4703D0AC7DCD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXIc      ', 0x560D0000010505000000CDCCCCCCCCEEAC40A4703D0A879AD740CDCCCCCCCCE2AE4066666666869AD740CDCCCCCCCCE2AE4066666666067AD740CDCCCCCCCCEEAC40A4703D0A077AD740CDCCCCCCCCEEAC40A4703D0A879AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XXc       ', 0x560D0000010505000000CDCCCCCCCCE2AE4066666666869AD740666666666601B14066666666869AD740666666666601B14066666666067AD740CDCCCCCCCCE2AE4066666666067AD740CDCCCCCCCCE2AE4066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XVIc      ', 0x560D0000010505000000666666666601B14066666666067AD740666666666671B140A4703D0A077AD740666666666671B140A4703D0A8759D740666666666601B140A4703D0A8759D740666666666601B14066666666067AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'lc        ', 0x560D0000010505000000666666666601B14066666666869AD740666666666671B14066666666869AD740666666666671B140A4703D0A077AD740666666666601B14066666666067AD740666666666601B14066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'XVla      ', 0x560D0000010505000000666666666671B140A4703D0A077AD7406666666666A5B240A4703D0A077AD7406666666666A5B240A4703D0A8759D740666666666671B140A4703D0A8759D740666666666671B140A4703D0A077AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'Ia        ', 0x560D00000105060000006666666666A5B240EC51B81EC5F5D7406666666666A5B24066666666869AD740666666666671B14066666666869AD740666666666601B14066666666869AD740666666666601B140A4703D0AC7F5D7406666666666A5B240EC51B81EC5F5D740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'Ila       ', 0x560D00000105050000006666666666A5B24066666666869AD740666666666635B44066666666869AD740666666666635B4404C378941C8F5D7406666666666A5B240B4C876BEC7F5D7406666666666A5B24066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)
INSERT [dbo].[HOarea] ([HOarea], [GEOM]) VALUES (N'IIIa      ', 0x560D0000010505000000666666666635B44066666666869AD7406666666666C5B54066666666869AD7406666666666C5B540105839B4C8F5D740666666666635B4404C378941C8F5D740666666666635B44066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003)

CREATE TABLE [dbo].[grid1600](
    [grid1600] [int] NULL,
    [GEOM] geometry NULL,
    [HOarea] [nvarchar](255) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (662, 0x560D00000105050000005E8DF893669DB5403333333363E1D7405E8DF893669DB5403333333343D7D7405E8DF8936675B5403333333343D7D7405E8DF8936675B5403333333363E1D7405E8DF893669DB5403333333363E1D7400000000000000000000000000000000000000000000000000000000000000000000000000000000001000000020000000001000000FFFFFFFF0000000003, NULL)
INSERT [dbo].[grid1600] ([grid1600], [GEOM], [HOarea]) VALUES (662, 0x560D0000010505000000666666666635B44066666666869AD7406666666666C5B54066666666869AD7406666666666C5B540105839B4C8F5D740666666666635B4404C378941C8F5D740666666666635B44066666666869AD740000000000000F8FF000000000000F8FF000000000000F8FF000000000000F8FF000000000000000001000000020000000001000000FFFFFFFF0000000003, NULL)

声明:

SELECT a.grid1600, a.GEOM 
FROM [dbo].[grid1600] a 
JOIN [dbo].[HOarea] b ON 
   (a.grid1600 = 662) AND 
   (b.GEOM.STWithin(a.GEOM) = 1)

结果:

grid1600    GEOM                                                                
662         POLYGON ((5173.4 24170.1, 5573.4 24170.1, 5573.4 24535.136, 5173.4 24535.129, 5173.4 24170.1 0))