这里是我的SQL查询:偶尔发生:“错误转换数据类型为nvarchar浮动”
SELECT (CAST(CAST([rssi1] AS float) AS INT))*-1, CONVERT(VARCHAR(10), [date], 110)
FROM history
WHERE id IN
(
SELECT TOP 8 id
FROM history
WHERE ([siteName] = 'CAL00022')
ORDER BY id DESC
)
ORDER BY date ASC
大多数时候,它工作正常。 有时候,我得到这个错误:
Server Error in '/' Application.
Error converting data type nvarchar to float.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Error converting data type nvarchar to float.
表是这样的:
那是你的整个表?你可能在'rssi1'中至少有一个值不是有效的浮点数.. – Blorgbeard
好吧,这显然不是导致问题的数据。 'SELECT * FROM history ORDER BY id'是什么让你知道其余的数据? –