2013-01-24 60 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

沒有意識到(明顯)。謝謝! –

相關問題