2014-06-13 69 views
0

我有這個存儲過程:存儲過程的錯誤轉換數據類型爲nvarchar到數字

ALTER PROCEDURE NearUnits 
    @lat float, 
    @lng float 
AS 
BEGIN 
SELECT * 
FROM 
(
    SELECT Uname, Latitude, Longitude,Info, 
    (
    6371 * acos(
     sin(@lat/57.295800) * 
     sin(Latitude/57.295800) + 
     cos(@lat/57.295800) * 
     cos(Latitude/57.295800) * 
     cos(@lng/57.295800 - Longitude/57.295800) 
    ) 
) AS distance 
    FROM [dbo].[MedicalUnit] 
) mytable 
WHERE distance <= 20; 
END; 

當我執行它:

NearUnits 31.0333449532716,31.3618322632 

我得到這個錯誤:

Msg 8114, Level 16, State 5, Procedure NearUnits, Line 6 Error converting data type nvarchar to numeric.

雖然它之前正常工作!

任何解決方案??

+1

什麼是表的架構? – Mark

+0

抱歉,您對模式有何意義? –

+0

Schema是數據類型pif表的列和它的鍵可能指示 - 但是你應該在做andy SQL之前知道這一點,我會重讀你的教程 - 如果你不明白這個詞,可能會有其他的東西,你在我們的答覆中不會理解 – Mark

回答

0

托盤鑄造經緯度:

ALTER PROCEDURE NearUnits 
    @lat float, 
    @lng float 
AS 
BEGIN 
SELECT * 
FROM 
(
    SELECT Uname, Latitude, Longitude,Info, 
    (
    6371 * acos(
     sin(@lat/57.295800) * 
     sin(CAST(Latitude AS float)/57.295800) + 
     cos(@lat/57.295800) * 
     cos(CAST(Latitude AS float)/57.295800) * 
     cos(@lng/57.295800 - CAST(Longitude AS float)/57.295800) 
    ) 
) AS distance 
    FROM [dbo].[MedicalUnit] 
) mytable 
WHERE distance <= 20; 
END; 
相關問題