Link to home
Create AccountLog in
Avatar of grantballantyne
grantballantyneFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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
Avatar of ralmada
ralmada
Flag of Canada image

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

Avatar of kaufmed
DECLARE @polyline GEOGRAPHY;

Shouldn't that be "polygon" and not "polyline"?
In fact you declared for @polyline, and used @polygon in your query.
 please change it as @polyline in the Query. that'll do.

Is  GEOGRAPHY a valid SQL Server Data Type !
Avatar of ambidextrous
ambidextrous

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

> Is  GEOGRAPHY a valid SQL Server Data Type !

Are you stuck in 2005? Check 2008 books online
Avatar of grantballantyne

ASKER

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

@cyberkiwi
Seems I'm a little behind
ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
actually it looks liek you have them inverted

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