you need to break the equation down into its separate components, and return the sub-component solution with an inner select statement, of a group of nested selects.

case when e.employeecode = '1011' and count(distinct tpps.sequencenumber) = 2 then 180

when e.employeecode = '1011' and count(distinct tpps.sequencenumber) = 3 then 270

when e.employeecode <> '1011' and count(distinct tpps.sequencenumber) = 2 then 160

when e.employeecode <> '1011' and count(distinct tpps.sequencenumber) = 3 then 240 end

is a sub-component, and

count(distinct tpps.sequencenumber)

may be a sub-component of it. (can't tell with what you posted)

so it would look something like

```
select Sum(case Hour_Qty_Code when 'Hrs' then FTEhours when 'Qty' then Quantity else 0 end / divisor) as [Month]
from
(
Select Case When ha.AllowanceCode IN
('100','130','AL','BL','BL1','DL','JS','LD','LSL','MU','NWA1','SP','R','SL','SSL','ST','T OILT') THEN 'Hrs'
WHEN ha.AllowanceCode IN('120', '150','ACC','ACC1','AOT','LN','NWA') THEN 'Qty'
else 'NA' end as Hour_Qty_Code,
ha.FTEhours,
ha.Quantity,
case when e.employeecode = '1011' and SeqCount = 2 then 180
when e.employeecode = '1011' and SeqCount = 3 then 270
when e.employeecode <> '1011' and SeqCount = 2 then 160
when e.employeecode <> '1011' and SeqCount = 3 then 240 end as divisor
from
ha
join e on ha.id = e.id
join
(select count(distinct tpps.sequencenumber) SeqCount, id from tpps group by id)
as sqnm on ha.id = sqnm.id
)
as subcomponent
```