2013-01-24 131 views
0

我试图做使用SQL Server 2008的基本近似搜索(通过经/纬度指定位置,使返回的结果是从位置的距离排序表中的位置)。SQL Server 2008的:必须声明标量变量(地理)

我有一个在SQL Server中的作品完美的代码。但是,当我尝试从ASP/VBScript中内执行它(不要问),我收到以下错误:

Must declare the scalar variable '@currentPosition' (refers to line commented below)

这里是代码:

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 

我有自己的变量声明(或者至少我认为我是这样做的),但显然我错过了一些东西或者做得不正确。希望有人比我聪明能告诉我什么:)

谢谢您的时间。

+0

我要澄清运行...实际的错误是一个线下的执行线之上突出。但错误是在下一次尝试执行,这是我最初强调的。 –

回答

1

你需要Concat的所有命令在一个字符串中的单个Execute

+0

没有意识到(明显)。谢谢! –

相关问题