我正在尝试使用 SQL Server 2008 进行基本的邻近搜索(传递指定位置的纬度/经度,以便返回的结果是按位置距离排序的表中的位置)。
我有在 SQL Server 中完美运行的代码。但是,当我尝试从 ASP/VBScript 中执行它时(不要问),我收到以下错误:
必须声明标量变量“@currentPosition”(参考下面注释的行)
这是代码:
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
我声明了变量(或者至少我认为我声明了),但显然我遗漏了一些东西或做错了。希望比我聪明的人能告诉我什么:)
感谢您的时间。