TIMEFROMPARTS (Transact-SQL)
本文內容
適用於:SQL Server
Azure SQL 資料庫
Azure SQL 受控執行個體
Azure Synapse Analytics
Analytics Platform System (PDW)
傳回包含指定精確度之指定時間的 time 值。
TIMEFROMPARTS ( hour, minute, seconds, fractions, precision )
hour
指定小時的整數運算式。
minute
指定分鐘的整數運算式。
seconds
指定秒的整數運算式。
fractions
指定分數的整數運算式。
有效位數
指定要傳回之 time 值的精確度的整數常值。
time(precision)
TIMEFROMPARTS 會傳回完整初始化的時間值。 如果引數無效,將會引發錯誤。 如有任何參數為 null,會傳回 null。 然而,若 precision 引數為 Null,則會引發錯誤。
fractions 引數相依於 precision 引數。 例如,假設 precision 為 7,每個分數即表示 100 奈秒;如果 precision 為 3,每個分數即表示 1 毫秒。 如果 precision 的值為零,fractions 也必須為零,否則將引發錯誤。
這個函式可以遠端處理到 SQL Server 2012 (11.x) 和更新版本的伺服器。 其無法遠端處理到版本低於 SQL Server 2012 (11.x) 的伺服器。
SELECT TIMEFROMPARTS ( 23, 59, 59, 0, 0 ) AS Result;
結果集如下所示。
Result
--------------------
23:59:59.0000000
(1 row(s) affected)
以下範例示範 fractions 和 precision 參數的用法:
若 fractions 的值為 5、precision 的值為 1,則 fractions 的值表示 5/10 秒。
若 fractions 的值為 50、precision 的值為 2,則 fractions 的值表示 50/100 秒。
若 fractions 的值為 500、precision 的值為 3,則 fractions 的值表示 500/1000 秒。
SELECT TIMEFROMPARTS ( 14, 23, 44, 5, 1 );
SELECT TIMEFROMPARTS ( 14, 23, 44, 50, 2 );
SELECT TIMEFROMPARTS ( 14, 23, 44, 500, 3 );
GO
結果集如下所示。
----------------
14:23:44.5
(1 row(s) affected)
----------------
14:23:44.50
(1 row(s) affected)
----------------
14:23:44.500
(1 row(s) affected)