我想在我的SQL中查看前3個月的會話小時數(hrs
列聲明爲nvarchar
),如果我想查看數據,則需要將數據轉換爲浮點數最近3個月,但我得到了一些錯誤將nvarchar轉換爲在SQL Server中浮動時出錯
SELECT sum(convert(float, hrs))
FROM companysonvinunitvenue
WHERE date >= DATEADD(day, -90, GETDATE())
錯誤:
Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to float.
SELECT sum(cast(hrs as float))
FROM companysonvinunitvenue
WHERE date >= DATEADD(day, -90, GETDATE())
錯誤:
Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to float.
SELECT CAST(CAST (hrs AS NUMERIC(19,4)) AS INT)
FROM companysonvinunitvenue
WHERE date >= DATEADD(day, -90, GETDATE())
錯誤:
Msg 8114, Level 16, State 5, Line 1
Error converting data type nvarchar to numeric.
SELECT CAST(CAST (hrs AS int) AS INT)
FROM companysonvinunitvenue
WHERE date >= DATEADD(day, -90, GETDATE())
錯誤:
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the nvarchar value '02:00:00 ' to data type int.
我想這四種方式,並在所有的人都失敗了,我需要怎麼做呢?
如果'hrs'表示** **時間 - 那麼爲什麼地球上被它定義爲'nvarchar'?修正你的有缺陷的設計 - 如果它**是一個數值,那麼它**也需要被存儲**。我會避免因其不精確性而使用「float」,而使用「decimal(p,s)」 –