I have three fields - starttime, duration (in hours), and endtime in mssql 2008 r2. Starttime and duration are entered in a form by endusers and I attempted to define trigger to insert/update endtime (as 1 minute less than the starttime+duration) use TIMEFROMPARTS as below (just querying in Management studio) but failed!!!:
Select (DATEPART,Starttime),Duration, TIMEFROMPARTS(DATEPART(HOUR,starttime) + Duration -1,59,0,0,0) As EndTime from <tablename>
but it failed with the message:
Msg 195, Level 15, State 10, Line 1
'TIMEFROMPARTS' is not a recognized built-in function name.
where as this URL of msdn talks about this function:
https://msdn.microsoft.com/en-us/library/hh213398.aspx?f=255&MSPPError=-2147217396
---
Appreciate if there is a clear reason why the function doesn't work and there is a simple fix (simple means other than upgrading database..etc.) Otherwise, I will have to resort to convert to datetime from time (for starttime) , use DateAdd function to get the new datetime and then get timepart for end time!!!
rmrrdesai
It is actually getting weird..even DATEFROMPARTS did not work either. My attempt to:
DATEFROMPARTS(YEAR(StartDate),DATEPART(hour,starttime)+Duration01,59) As endtime failed as well!!!
Similar error message..'DATEFROMPARTS' is not a recognized buil-in function name.