SQL Flow Field Guide

geometry.AsBinaryZM

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

spatial method AsBinaryZM (instance.AsBinaryZM(...))

What changes

Input
spatial instance (and arguments)
Output or change
varbinary(max)
Return type
SQL Server return type: varbinary(max) CLR return type: SqlBytes

Syntax at a glance

.AsBinaryZM()

Work example

Use geometry.AsBinaryZM to export binary coordinates with Z and M ordinates.

Confirm the destination supports the same dimensions and SRID. Keep the geometry type and SRID in the review.

Check your work The binary result carries Z and M ordinates. Coordinates remain in the geometry plane.

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 @shape geometry;
SET @shape = geometry::STGeomFromText(N'LINESTRING(0 0 2 10, 3 4 5 20)', 0);
SELECT @shape.AsBinaryZM() AS route_wkb_with_zm,
       @shape.STSrid AS source_srid,
       @shape.STIsValid() AS source_is_valid;

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