SQL Flow Field Guide

geometry::STGeomFromText

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

static constructor STGeomFromText (called as type::STGeomFromText(...))

What changes

Input
WKT, WKB, GML or coordinates and SRID
Output or change
spatial instance
Return type
SQL Server return type: geometry CLR return type: SqlGeometry

Syntax at a glance

STGeomFromText ( 'geometry_tagged_text' , SRID )

Work example

Use geometry.STGeomFromText to construct a spatial instance from WKT.

Choose geometry for planar coordinates or geography for earth coordinates and set its SRID. Keep the geometry type and SRID in the review.

Check your work The generic WKT constructor returns a polygon with one valid interior ring.

Practice SQL

Open in SQL Flow

Open the SQL for a walkthrough. Run the example in SQL Server to check its result.

-- Planar geometry. SRID 0 coordinates here are synthetic units, not metres.
DECLARE @result geometry;
SET @result = geometry::STGeomFromText(N'POLYGON((0 0, 10 0, 10 10, 0 10, 0 0),(2 2, 2 4, 4 4, 4 2, 2 2))', 0);
SELECT @result.STAsText() AS polygon_with_hole,
       @result.STSrid AS result_srid,
       @result.STIsValid() AS result_is_valid;

Open Microsoft Learn for full syntax, permissions, and details for your version.