Hi,
Try these Queries
select employee, sum(datediff(dd,begindate,enddate))
from detailtable dt
where dt.begindate between 'thestartdate' and 'theenddate'
and exists (select 1 from detailtable dt2
where dt.employee = dt2.employee
and type not in (1, 5, 6))
group by emaployee
having sum(datediff(dd,begindate,enddate)) > 40
OR
Select * From
(select employee, sum(datediff(dd,begindate,enddate)) SumTotDiff
from detailtable dt
where dt.begindate between 'thestartdate' and 'theenddate'
and exists (select 1 from detailtable dt2
where dt.employee = dt2.employee
and type not in (1, 5, 6))
group by emaployee) TBL Where SumTotDiff>40
Hope it helps
Sunil