# Minimum and Maximum Points For A Series of Geometry Data Types

Staff member
After bringing in a series of Shapefiles into SQL Server 2008R2 we are looking to grab the min and maximum points for a series of polygons in a table.

Without aggregate functions like STExtent in SQL Server 2008R2 how can one determine the min and maximum points?

This blog post points to a series of options:<br>
<a href="http://alastaira.wordpress.com/2011...nt-of-spatial-features-in-a-sql-server-table/" rel="nofollow">http://alastaira.wordpress.com/2011...nt-of-spatial-features-in-a-sql-server-table/</a>

<ul>
<li>Option #1 : With a Cursor</li>
<li>Option #2 : CLR Function</li>
<li>Option #3 : CTE</li>
<li>Option #4 : Persisted Envelopes</li>
</ul>

An example:

Code:
BEGIN TRAN
CREATE TABLE #Lines
(
ID INT IDENTITY(1,1)
,Poly GEOMETRY NULL
);

INSERT INTO #Lines
(Poly)
VALUES
(geometry::STGeomFromText('LINESTRING(0 0, 2 3)', 0));

INSERT INTO #Lines
(Poly)
VALUES
(geometry::STGeomFromText('LINESTRING(1 1, 2 4)',0));

--How can i get the min and max x and y points?
--(e.g. for this example Xmin = 0, Xmax = 2, Ymin = 0, Ymax = 4)

DROP TABLE #Lines
COMMIT