Export (0) Print
Expand All

MinDbCompatibilityLevel (geography Data Type)

Returns the minimum database compatibility that recognizes the geography data type.

Applies to: SQL Server (SQL Server 2012 through current version), Azure SQL Database.

. MinDbCompatibilityLevel ( )

SQL Server return type: int

CLR return type: int

Use MinDbCompatibilityLevel() to test a spatial object for compatibility before changing the compatibility level on a database. An invalid geography type returns 110.

A. Testing CircularString type for compatibility with compatibility level 110

The following example tests a CircularString instance for compatibility with an earlier version of SQL Server:

DECLARE @g geometry = 'CIRCULARSTRING(-120.533 46.566, -118.283 46.1, -122.3 47.45)';
IF @g.MinDbCompatibilityLevel() <= 110
BEGIN
    SELECT @g.ToString();
END

B. Testing LineString type for compatibility with compatibility level 100

The following example tests a LineString instance for compatibility with SQL Server 2008:

DECLARE @g geometry = 'LINESTRING(-120.533 46.566, -118.283 46.1, -122.3 47.45)';
IF @g.MinDbCompatibilityLevel() <= 100
BEGIN
    SELECT @g.ToString();
END

C. Testing the value of a Geography instance for compatibility

The following example shows the compatibility levels for two geography instances. One is smaller than a hemisphere and the other is larger than a hemisphere:

DECLARE @g geography = geography::Parse('POLYGON((0 -10, 120 -10, 240 -10, 0 -10))');
DECLARE @h geography = geography::Parse('POLYGON((0 10, 120 10, 240 10, 0 10))');
IF (@g.EnvelopeAngle() >= 90)
BEGIN
SELECT @g.MinDbCompatibilityLevel();
END   
IF (@h.EnvelopeAngle() < 90)
BEGIN
SELECT @h.MinDbCompatibilityLevel();
END   

The first SELECT statement returns 110 and the second SELECT statement returns 100.

Community Additions

ADD
Show:
© 2014 Microsoft