with Age (SessionID, NewAgeDescription) as ( SELECT SessionID, dbo.GetAgeDescriptionFromSeconds((SELECT dbo.GetNewAge(rp.ProcessStarted, ISNULL(rp.ProcessEnded, GETDATE()), 1, 0, rp.SessionID))) FROM dbo.ReportProcess AS rp WITH (NOLOCK) WHERE (ServiceID <> 'SERVICEDESK-EMAIL INBOUND') ) select a.SessionID, case when a.NewAgeDescription = '0' then (select dbo.GetAgeDescriptionFromSeconds(DATEDIFF(SECOND, rp.ProcessStarted, ISNULL(rp.ProcessEnded, GETDATE()))) from ReportProcess rp where a.SessionID = rp.SessionID) else a.NewAgeDescription end as [NewAgeDescription] from Age a