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?
 
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
 
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
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
 
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:
actually it looks liek you have them inverted

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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.