Click here to Skip to main content
12,554,442 members (88,266 online)
Rate this:
Please Sign up or sign in to vote.
See more: T-SQL
During the purposeful misuse of a geography data type:

DECLARE @gxxx geography;
SET @gxxx = geometry::STGeomFromText('POLYGON((-118.934303 40.883523, -72.279144 42.769298, -73.991066 40.739213, -105.828393 28.568069, -118.934303 40.883523))',0);
SELECT @gxxx.STArea();

I get this error:

"Msg 206, Level 16, State 2, Line 2
Operand type clash: sys.geography is incompatible with sys.geometry"

So I was wondering, even looked up the object in help:

SELECT * FROM sys.geometry


SELECT * FROM sys.geography

Should return something, no?

There's no such thing as sys.geography or sys.geometry ... so how is this an error message?

(Yes, I CAN see that my T-SQL disdirection is evil .. hence the title content)
Posted 24-Oct-12 8:38am
Updated 24-Oct-12 8:55am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Unless you have created the table sys.geometry and sys.geography you would simply get an "Invalid object name 'sys.geometry' which is entirely valid as the tables don't exist.

geometry and geography are System Data Types so they can't be interchanged with each other so of course you'll get the Operand type clash error.

Either I'm missing something in your question, or everything is as it should be.
RedDK 24-Oct-12 14:51pm

I saw that there's no object. And that invalidates any time factor during my query because there's nothing to point my question at.

But using reverse logic then, doesn't "sys." get prefixed to EVERY variable I use in a DECLARE statement?

Really, there's nothing to be missed. My original error geography/geometry swap cancels any rational question about the returns from the interface at rt but it's that old %-substitution that's tiggering my curiosity about how the error is generated.
Marcus Kramer 24-Oct-12 14:54pm
The system is trying to auto cast your geometry type to a geography type, so the = operand is the action where the error occurs, so operand type clash is what you get.
RedDK 24-Oct-12 15:01pm
Got it,

Incidently, after adding the "close" coordinates for proper "geography", and correcting the clash by making everything geopgraphy:

DECLARE @gxxx geography;

SET @gxxx = geography::STGeomFromText('POLYGON((-118.934303 40.883523, -72.279144 42.769298, -73.991066 40.739213, -105.828393 28.568069, -118.934303 40.883523))',4326);

SELECT @gxxx.STArea();

I get another error ... Msg 6522 ... (sp) " ... The specified input does not represent valid geography because it exceeds a single hemisphere" ...

Too much information?The next peice of the message goes:

" A common reason for this error is that a polygon has the wrong ring orientation."

On to more investigation ...Thanks Marcus!


For completeness' sake, some good form and something that looks like a plausible answer:

DECLARE @gxxx geometry;

SET @gxxx = geometry::STGeomFromText('POLYGON((337031.58 4527628.01, 722607.00 4738786.85, 585187.12 4510297.40, 418979.91 3160412.97, 337031.58 4527628.01))',0);

SELECT @gxxx.STArea();

Query answer:198472128803.033

Cool ...


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.161021.1 | Last Updated 24 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100