TIMEFROMPARTS (Transact-SQL)TIMEFROMPARTS (Transact-SQL)

語法Syntax

``````TIMEFROMPARTS ( hour, minute, seconds, fractions, precision )
``````

引數Arguments

hourhour

minuteminute

secondsseconds

fractionsfractions

傳回類型Return Types

time( precision )time( precision )

RemarksRemarks

TIMEROMPARTS 會傳回完整初始化的時間值。TIMEROMPARTS returns a fully initialized time value. 如果引數無效，將會引發錯誤。If the arguments are invalid, then an error is raised. 如有任何參數為 null，會傳回 null。If any of the parameters are null, null is returned. 然而，若 precision 引數為 Null，則會引發錯誤。However, if the precision argument is null, then an error is raised.

fractions 引數相依於 precision 引數。The fractions argument depends on the precision argument. 例如，假設 precision 為 7，每個分數即表示 100 奈秒；如果 precision 為 3，每個分數即表示 1 毫秒。For example, if precision is 7, then each fraction represents 100 nanoseconds; if precision is 3, then each fraction represents a millisecond. 如果 precision 的值為零，fractions 也必須為零，否則將引發錯誤。If the value of precision is zero, then the value of fractions must also be zero; otherwise, an error is raised.

範例Examples

A.A.不包含秒的小數部分的簡單範例Simple example without fractions of a second

``````SELECT TIMEFROMPARTS ( 23, 59, 59, 0, 0 ) AS Result;
``````

``````Result
--------------------
23:59:59.0000000

(1 row(s) affected)
``````

B.B.含秒的小數部分的範例Example with fractions of a second

1. fractions 的值為 5、precision 的值為 1，則 fractions 的值表示 5/10 秒。When fractions has a value of 5 and precision has a value of 1, then the value of fractions represents 5/10 of a second.

2. fractions 的值為 50、precision 的值為 2，則 fractions 的值表示 50/100 秒。When fractions has a value of 50 and precision has a value of 2, then the value of fractions represents 50/100 of a second.

3. fractions 的值為 500、precision 的值為 3，則 fractions 的值表示 500/1000 秒。When fractions has a value of 500 and precision has a value of 3, then the value of fractions represents 500/1000 of a second.

``````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)
``````