Skip to content

Case Statement

 

Below is an example demonstrating the use of the 'Case' statement

select
C.CCENTREID,
C.NAME as Cost_Centre,
sum(SC.ESTTIME) as "CM_Hrs",
sum(SC.SUBTOTALCOST) as "CM_Amount",

case
when (C.NAME = 'Parva') then (sum(SC.QTY)*2)
when (C.NAME = 'GTO 46') then (sum(SC.QTY)/2)
else sum(SC.QTY)
end

from SOCOSTS SC
left join CCENTRE C on SC.CCID = C.CCENTREID
left join SOMAIN S on SC.SOID = S.SOID
where S.INVDATE between :DATESTART and :DATEEND
and SC.CCID > 0
and C.COSTTYPE = 'Printing'

group by C.CCENTREID, C.NAME, C.COSTTYPE
order by C.NAME