WHERE TERM_DATE_DATE9 is nulland [Is Lead?] = 'No'and IS_MANAGER = 0 and PP_NUMBER like '[A-Z]%'and UPPER(EmpGroupName) not like ('%ADMIN%')and UPPER(EmpTeamName) not like '%ADMIN%'and LTRIM(RTRIM(Lucent_Log_new)) != ''and Lucent_Log_new is not null

where NOM_DATE between @startdate and @enddate )--------------- end of CTE ------------------------

SELECT @startdate BegDate,@enddate EndDate,wadb.EmpDivisionName,wadb.EmpGroupName,wadb.EmpTeamName,wadb.Employee,Cast(ISNULL(['*FLEX'],0) as decimal(18,2)) FLEX,Cast(ISNULL([*FLEX OFF],0) as decimal(18,2)) FLEXOFF,Cast(ISNULL([*FLEX OFF ABS],0) as decimal(18,2)) FLEXOFFABS--,Cast(ISNULL([FLEX OFF FHO],0) as decimal(18,2)) FLEXOFFFHO--,Cast(ISNULL([FLEX OFF PER],0) as decimal(18,2)) FLEXOFFPER--,Cast(ISNULL([FLEX OFF VAC],0) as decimal(18,2)) FLEXOFFVAC--,Cast(ISNULL([FLEX OFF PAID],0) as decimal(18,2)) FLEXOFFPAID--,Cast(ISNULL([FLEX OFF UNPAID],0) as decimal(18,2)) FLEXOFFUNPAID--,Cast(ISNULL([FLEX ON],0) as decimal(18,2)) FLEXON,cast(cast(sum(seg.MI) as decimal (10,2))/60 as decimal (10,2)) hrs

from wadbleft outer joinsegON seg.EMP_ID = wadb.LucID

--where CODE in ('*UNPLANNED ABSENCES','*FLEX OFF CODES')where CODE in ('*FLEX','*FLEX OFF','*FLEX OFF ABS','*FLEX OFF AWARD','*FLEX OFF CODES','*FLEX OFF FHOFF','*FLEX OFF PAID','*FLEX OFF PERSONAL DAY','*FLEX OFF UNPAID','*FLEX OFF VAC','*FLEX.OFF PAID>Flex On (Empowe','*FLEX.ON>Flex Off Paid (Empowe')

PIVOT (SUM(hrs)FOR CODE IN'*FLEX','*FLEX OFF','*FLEX OFF ABS','*FLEX OFF AWARD','*FLEX OFF CODES','*FLEX OFF FHOFF','*FLEX OFF PAID','*FLEX OFF PERSONAL DAY','*FLEX OFF UNPAID','*FLEX OFF VAC','*FLEX.OFF PAID>Flex On (Empowe','*FLEX.ON>Flex Off Paid (Empowe') pvt