geometry.STAsText
spatial method STAsText (instance.STAsText(...))
What changes
- Input
- spatial instance (and arguments)
- Output or change
- nvarchar(max)
- Return type
- SQL Server return type: nvarchar(max) CLR return type: SqlChars
Syntax at a glance
.STAsText ( )
Work example
Use geometry.STAsText to export OGC Well-Known Text.
Check whether the consumer needs Z or M ordinates. Keep the geometry type and SRID in the review.
Check your work STAsText gives OGC WKT. Use AsTextZM when Z and M ordinates must be retained.
Practice SQL
Open in SQL FlowOpen 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 @shape geometry;
SET @shape = geometry::STGeomFromText(N'POINT(3 4 5 6)', 0);
SELECT @shape.STAsText() AS point_wkt,
@shape.STSrid AS source_srid,
@shape.STIsValid() AS source_is_valid;
Open Microsoft Learn for full syntax, permissions, and details for your version.