我在傳統的ASP頁面上使用以下SQL語法。 HostLatitude
不幸是nvarchar(20)
,因此十進制轉換。SQL生成錯誤
SELECT
HostID, HostLatitude, HostLongitude, HostNames, HostPropertyName,
HostStreet, HostSuburb, HostCity, HostPhone, HostMobile,
HostLastUpdated, HostJoinDate, HostPostCode, hgbCounter, HostStateID
FROM
Hosts
WHERE
HostLatitude IS NOT NULL
AND Datalength(HostLatitude) > 5
AND CONVERT(decimal, HostLatitude) > 51
AND CONVERT(decimal, HostLatitude) < 53
AND HostRegionID = 303
AND HostLastUpdated >CONVERT(DATETIME, '2012-02-21 00:00:00', 102) - 730
AND Datalength(HostLatitude) > 2
AND Datalength(HostLongitude) > 1
AND HostApproved = 1
AND HostDisabled = 0
AND AdminDisabled = 0
ORDER BY
HostID DESC;
我收到以下錯誤:
Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to numeric.
如果我註釋掉下面的查詢運行:
AND CONVERT(decimal, HostLatitude) > 51
AND CONVERT(decimal, HostLatitude) < 53
是什麼HostLatitude價值?我認爲有一些值不能轉換爲十進制,請檢查表中HostLatitude的值。 – 2012-02-21 05:36:30
您是否認爲它可能與本專欄的*內容*有關,因此可能值得向我們展示一些示例值? – 2012-02-21 05:39:56
@Damien_The_Unbeliever你是否認爲,也許,如果他意識到他不需要提出這個問題;) – 2012-02-21 05:41:24