case when query - SalindaPriyaranga/test GitHub Wiki
select COMPANYCODE,CREATIONTIMESTAMP,CODE,INVOICEDATE,sum(PRIMARYQTY) as PRIMARYQTY,SIZEHTSCODE, TPNNO,MEASUREMENTCTN,SIZEDESC,max(SIZESEQ) as SIZESEQ,SPLIT,PACKINGFLAG, case when PACKINGFLAG = '1' then sum(NOOFCARTNS) else max(NOOFCARTNS) end as NOOFCARTNS from( select COMPANYCODE,CREATIONTIMESTAMP,CODE,INVOICEDATE,PRIMARYQTY,SIZEHTSCODE,TPNNO,MEASUREMENTCTN,SIZEDESC,SPLIT,SIZESEQ,PACKINGFLAG, decimal(NOOFCARTNS,4) as NOOFCARTNS from WRKASDAINVOICE where CREATIONTIMESTAMP = 22221 --and split = null )
group by COMPANYCODE,CREATIONTIMESTAMP,CODE,INVOICEDATE,SIZEHTSCODE,TPNNO,MEASUREMENTCTN,SIZEDESC,SPLIT,PACKINGFLAG