2013-06-22 77 views
3

我試圖建立一個商店定位器,並且在構建我的sql語句時遇到了麻煩。我見到目前爲止如下:按經度和緯度排序的距離

SELECT TOP 3 Custno 
    , (3959 
     * acos(cos(radians(36)) 
      * cos(radians(Latitude)) 
      * cos(radians(Longitude) - radians(120)) 
      + sin(radians(120)) * sin(radians(Latitude)) 
     ) 
     ) AS distance 
FROM Customers 
ORDER BY distance 

當我運行這句話我得到:

Msg 0, Level 11, State 0, Line 0 
A severe error occurred on the current command. 
The results, if any, should be discarded. 

然而,當我一條一條地刪除訂單,當我by子句更改爲使用查詢工作Custno。什麼是造成這個錯誤,我怎樣才能避免它?

+2

有沒有在錯誤日誌中詳細?根據此處的說明在Management Studio中查找錯誤日誌:http://msdn.microsoft.com/en-us/library/ms187109.aspx –

+0

我無權訪問錯誤日誌,我只能訪問一個數據庫在服務器上。 – LT999

+0

客戶表是巨大的嗎?或者你可以插入一個臨時表,計算距離?這不會用於生產,只是爲了調試問題。 –

回答

相關問題