The following query returns dates in terms of hours,minutes,seconds.
SELECT LEFT(CONVERT(VARCHAR(10), ModifiedOn- CreatedOn, 108), 8) AS ResultTime from AssignedRoles
I have an extra field in the table AssignedRoles -“TurnAroundTime” where i would like to store the result generated from the query. Is this method effective, or is using a trigger a better option and if so kindly explain how to undertake it.
The database is a backend to an MVC C# application
Advertisement
Answer
I would recommend a computed column:
alter table AssignedRoles add turnAroundtime as (left(convert(varchar(10), ModifiedOn - CreatedOn, 108), 8))
This gives you an always up-to-date value that you don’t need to maintain manually, with almost zero extra code.