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

適用於: 是SQL Server 是Azure SQL Database 是Azure SQL 資料倉儲 是平行處理資料倉儲 APPLIES TO: yesSQL Server yesAzure SQL Database yesAzure SQL Data Warehouse yesParallel Data Warehouse

傳回包含指定精確度之指定時間的 time 值。Returns a time value for the specified time and with the specified precision.

主題連結圖示 Transact-SQL 語法慣例Topic link icon Transact-SQL Syntax Conventions

語法Syntax

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

引數Arguments

hourhour
指定小時的整數運算式。Integer expression specifying hours.

minuteminute
指定分鐘的整數運算式。Integer expression specifying minutes.

secondsseconds
指定秒的整數運算式。Integer expression specifying seconds.

fractionsfractions
指定分數的整數運算式。Integer expression specifying fractions.

有效位數precision
指定要傳回之 time 值的精確度的整數常值。Integer literal specifying the precision of the time value to be returned.

傳回類型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.

這個函數可以遠端處理到 SQL Server 2012 (11.x)SQL Server 2012 (11.x) 和更新版本的伺服器。This function can be remoted to SQL Server 2012 (11.x)SQL Server 2012 (11.x) servers and higher. 它無法遠端處理到版本低於 SQL Server 2012 (11.x)SQL Server 2012 (11.x) 的伺服器。It cannot be remoted to servers that have a version lower than SQL Server 2012 (11.x)SQL Server 2012 (11.x).

範例Examples

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

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

以下為結果集:Here is the result set.

Result  
--------------------  
23:59:59.0000000  
  
(1 row(s) affected)  

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

以下範例示範 fractionsprecision 參數的用法:The following example demonstrates the use of the fractions and precision parameters:

  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  

以下為結果集:Here is the result set.

----------------  
14:23:44.5  
  
(1 row(s) affected)  
  
----------------  
14:23:44.50  
  
(1 row(s) affected)  
  
----------------  
14:23:44.500  
  
(1 row(s) affected)