繁体   English   中英

SQL Server 2008:必须声明标量变量(地理区域)

[英]SQL Server 2008: Must Declare Scalar Variable (Geography)

我正在尝试使用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

我已经声明了变量(或者至少我认为是这样做的),但是显然我丢失了某些东西或做错了。 希望有人比我聪明可以告诉我什么:)

感谢您的时间。

您需要将所有命令合并为一个字符串,然后在一个Execute运行它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM