I don't really see what's so complex about this
You have the numbers:
DATEDIFF(minute,MealTimeIn,MealTimeOut) AS [MealBreak],
DATEDIFF(minute,TeaTimeIn,TeaTimeOut) AS [TeaBreak],
DATEDIFF(minute,StartTimeIn,EndTimeOut) AS [TimeSpent]
DATEDIFF(minute,MealTimeIn,MealTimeOut) - (DATEDIFF(minute,TeaTimeIn,TeaTimeOut) + DATEDIFF(minute,StartTimeIn,EndTimeOut)) as TotalSpentTime
If you have masses of data this can be inefficient (but you would need MASSES of data to notice)
If you're really worried about inefficiency then you could use CTE's (Common Table Expressions) to reduce the redundant duplicated calculations:
with test_data as (
select
'2016-10-10 11:48:00' as StartTimeIn,
'2016-10-10 16:18:00' as EndTimeOut,
'2016-10-10 11:58:00' as MealTimeIn,
'2016-10-10 12:15:00' as MealTimeOut,
'2016-10-10 13:06:00' as TeaTimeIn,
'2016-10-10 13:17:00' as TeaTimeOut
), calc_data as (
select
datediff(minute, StartTimeIn, EndTimeOut) as TimeSpent,
datediff(minute, TeaTimeIn,TeaTimeOut) as TeaBreak,
datediff(minute, MealTimeIn, MealTimeOut) as MealBreak
from test_data
), calc_total_data as (
select
TimeSpent,
TeaBreak,
MealBreak,
TimeSpent - (TeaBreak + MealBreak) as TotalSpentTime
from calc_data
)
select * from calc_total_data
Is that all? I get the feeling that I'm missing the issue.