I am attempting to do a basic proximity search using SQL Server 2008 (passing lat/long of specified position so that returned results are locations in table ordered by distance from position).
I have code that works perfectly within SQL Server. But, when I try to execute it from within ASP/VBScript (don't ask), I get the following error:
Must declare the scalar variable '@currentPosition' (refers to line commented below)
Here is the code:
objCommand.CommandText = "declare @currentLatitude float, @CurrentLongitude float"
objCommand.Execute
objCommand.CommandText = "declare @currentPosition geography"
objCommand.Execute
objCommand.CommandText = "declare @radiusBuffer geography"
objCommand.Execute
''''error line below:
objCommand.CommandText = "Set @radiusBuffer = @currentPosition.BufferWithTolerance(10 * 1609.344,.9,1);"
objCommand.Execute
objCommand.CommandText = "set @CurrentLatitude = 12.34567"
objCommand.Execute
objCommand.CommandText = "set @CurrentLongitude = -12.34567"
objCommand.Execute
objCommand.CommandText = "SET @currentPosition = geography::Point(@CurrentLatitude, @CurrentLongitude, 4326);"
objCommand.Execute
objCommand.CommandText = "SELECT a.*, ROW_NUMBER() OVER (ORDER BY GeoLocation.STDistance(@currentPosition) ASC) AS RowNum from table_name a WHERE a.GeoLocation.STDistance(@currentPosition) < 16093.44"
objCommand.Execute
I have the variable declared (or at least I think I do), but obviously I'm missing something or doing it incorrectly. Hopefully someone smarter than me can show me what :)
Thank you for your time.