Must declare the scalar variable @polygon"

Dear Experts

I am trying to run the following SQL Query:

DECLARE @polyline GEOGRAPHY;

SET @polygon = geography::Parse('POLYGON((47.0 -124.0, 47.0 -122.0,
50.0 -122.0, 50.0 -124.0, 47.0 -124.0))');

SELECT *
  from current_residential_geography
 where  
 @polygon.STIntersects(current_residential_geography.GeoLocation) = 1


However Iam getting the error message "Must declare the scalar variable "@polygon"

Can anyone advise where I am going wrong with the syntax?

Thanks
grantballantyneAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ralmadaCommented:
DECLARE @polygon GEOGRAPHY;

SET @polygon = geography::Parse('POLYGON((47.0 -124.0, 47.0 -122.0,
50.0 -122.0, 50.0 -124.0, 47.0 -124.0))');

SELECT *
  from current_residential_geography
 where  
 @polygon.STIntersects(current_residential_geography.GeoLocation) = 1

0
käµfm³d 👽Commented:
DECLARE @polyline GEOGRAPHY;

Shouldn't that be "polygon" and not "polyline"?
0
waltersnowslinarnoldCommented:
In fact you declared for @polyline, and used @polygon in your query.
 please change it as @polyline in the Query. that'll do.
0
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Ephraim WangoyaCommented:

Is  GEOGRAPHY a valid SQL Server Data Type !
0
ambidextrousCommented:
Hi...  I think your declare says @polyline instead of @polygon.  Would that fix the issue?


DECLARE @polyline GEOGRAPHY;

SET @polygon = geography::Parse('POLYGON((47.0 -124.0, 47.0 -122.0,
50.0 -122.0, 50.0 -124.0, 47.0 -124.0))');

SELECT *
  from current_residential_geography
 where  
 @polygon.STIntersects(current_residential_geography.GeoLocation) = 1

0
cyberkiwiCommented:
> Is  GEOGRAPHY a valid SQL Server Data Type !

Are you stuck in 2005? Check 2008 books online
0
grantballantyneAuthor Commented:
Thanks evryone

I have changed the syntax to:

DECLARE @polygon GEOGRAPHY;

SET @polygon = geography::Parse('POLYGON((47.0 -124.0, 47.0 -122.0,
50.0 -122.0, 50.0 -124.0, 47.0 -124.0))');

SELECT *
  from current_residential_geography
 where  
 @polygon.STIntersects(current_residential_geography.GeoLocation) = 1


However I am now getting the following error:

Msg 6522, Level 16, State 1, Line 3
A .NET Framework error occurred during execution of user-defined routine or aggregate "geography":
System.FormatException: 24201: Latitude values must be between -90 and 90 degrees.
System.FormatException:
   at Microsoft.SqlServer.Types.GeographyValidator.ValidatePoint(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.Validator.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.ForwardingGeoDataSink.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.CoordinateReversingGeoDataSink.BeginFigure(Double x, Double y, Nullable`1 z, Nullable`1 m)
   at Microsoft.SqlServer.Types.OpenGisWktReader.ParseLineStringText()
   at Microsoft.SqlServer.Types.OpenGisWktReader.ParsePolygonText()
   at Microsoft.SqlServer.Types.OpenGisWktReader.ParseTaggedText(OpenGisType type)
   at Microsoft.SqlServer.Types.OpenGisWktReader.Read(OpenGisType type, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.GeographyFromText(OpenGisType type, SqlChars taggedText, Int32 srid)
   at Microsoft.SqlServer.Types.SqlGeography.Parse(SqlString s)


Thanks
0
Ephraim WangoyaCommented:

@cyberkiwi
Seems I'm a little behind
0
ralmadaCommented:
looks like you need to use Geometry instead of Geography.

Please take a look at this discussion

http://social.msdn.microsoft.com/Forums/en/sqlspatial/thread/aaf07915-81b8-4978-b6ac-8085769471f1
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ralmadaCommented:
actually it looks liek you have them inverted

('POLYGON((-124.0 47.0, -122.0 47.0 ...

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.