本文介紹了如何在 SQL Server 中將時間類型變量除以 2的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個 TIME
類型的變量,我需要將這個變量的時間除以 2.
I have a variable of type TIME
, I need to divide the time of this variable by 2.
我的 SQL 代碼:
DECLARE @TEMPO AS TIME = '01:31:00'
SELECT (@TEMPO / 2 ) AS RESULT
--the result should be: 00:45:30
SQL Server 但是拋出一個錯誤:
SQL Server however throws an error:
操作數類型沖突:time 與 int 不兼容
Operand type clash: time is incompatible with int
歡迎任何幫助!
推薦答案
另一種選擇是將時間轉換為 datetime
再轉換為 float
,然后除以二.
Just another option is to convert the time to datetime
and then to float
, and then divide by two.
示例
DECLARE @TEMPO AS TIME = '01:31:00'
Select convert(time,convert(datetime,convert(float,convert(datetime,@Tempo))/2))
退貨
00:45:30.0000000
這篇關于如何在 SQL Server 中將時間類型變量除以 2的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!