SQL TIMEFROMPARTS function is one of the Date and Time Function, which will return a time value from the users specified time, and precision parts.
The basic syntax of the TIMEFROMPARTS Function in SQL Server is as follows:
TIMEFROMPARTS (day, hour, minute, seconds, fractions, precisions)
As you can see from the above syntax, this function accepts six arguments to build time with precision.
This SQL Server TIMEFROMPARTS function returns time data type as output. Here, the Fraction value will always depend upon the Precision. If the precision value is 2, then the value of the fraction must also be 2 (or less than 2); otherwise, it will throw an error.
SQL TIMEFROMPARTS Function Example
In this example, we will show you the use of SQL Server Time From Parts function
-- Example for SQL TIMEFROMPARTS Function SELECT TIMEFROMPARTS ( 10, 09, 18, 5, 1 ) AS Result SELECT TIMEFROMPARTS ( 10, 09, 18, 50, 2 ) AS Result SELECT TIMEFROMPARTS ( 10, 09, 18, 503, 3 ) AS Result -- Let me try the NULL values SELECT TIMEFROMPARTS ( NULL, 09, 18, 504, 3 ) AS Result -- Precision Value is greater than Fraction SELECT TIMEFROMPARTS ( 10, 09, 18, 503, 7 ) AS Result -- Precision Value is Les than Fraction. Invalid argument SELECT TIMEFROMPARTS ( 10, 09, 18, 503, 2 ) AS Result
As you can see from the above screenshot, the last statement is throwing an error. This is because, Fraction value = 503, and Precision = 2 (does not match). Let me show you the result