Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9192061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:50:09+00:00 2026-06-17T20:50:09+00:00

I am attempting to do a basic proximity search using SQL Server 2008 (passing

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:50:10+00:00Added an answer on June 17, 2026 at 8:50 pm

    You need to concat all the commands in one string and run it within a single Execute

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to do some basic parallelisation using _beginthreadex, and passing parameters as per
I'm attempting to write a very basic script using javascript. What I want to
I'm attempting to consume a HTTP Basic Auth Secured PHP WebService using VB.NET. I've
I have an image view in a basic app that I am attempting to
I'm attempting to do basic auth with Apache HTTPClient 4.x using the example from
I'm attempting to write a basic dna sequencer. In that, given two sequences of
I am attempting to add BASIC authentication to a RESTful web service that I
Basic form using a JQuery Accordion and attempting to validate required fields. Am I
I am attempting to create a simple java form using Swing. The idea basic
i am running a basic application using openCV for C++. I am attempting to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.