User49201036 posted
While using GroupBY Clause ,select query without aggregate function should be added in group by clause .
In your case select query i.e. staType,LineNum and RelateType should be added in group by clause
SELECT T0.DocEntry,T3.[ChapterID], Sum(T1.[LineTotal]),
ISNULL((Select (case when sum(T5.RvsChrgTax)<=0 then sum(T5.TaxSum/T0.DocRate) else 0 end) From INV4 T5 Where T5.DocEntry = T0.DocEntry and T5.staType = -100 and T5.LineNum = T1.LineNum and T5.RelateType = 1),0) [CGSTAmt],
ISNULL((Select (case when sum(T5.RvsChrgTax)<=0 then sum(T5.TaxSum/T0.DocRate) else 0 end) From INV4 T5 Where T5.DocEntry = T0.DocEntry and T5.staType = -110 and T5.LineNum = T1.LineNum and T5.RelateType = 1),0) [SGSTAmt],
ISNULL((Select (case when sum(T5.RvsChrgTax)<=0 then sum(T5.TaxSum/T0.DocRate) else 0 end) From INV4 T5 Where T5.DocEntry = T0.DocEntry and T5.staType = -120 and T5.LineNum = T1.LineNum and T5.RelateType = 1),0) [IGSTAmt]
FROM OINV T0
INNER JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry]
INNER JOIN OITM T2 ON T1.[ItemCode] = T2.[ItemCode]
INNER JOIN OCHP T3 ON T1.[HsnEntry] = T3.[AbsEntry]
LEFT OUTER JOIN INV4 T5 on T1.[DocEntry]=T5.[DocEntry] and T1.[LineNum]=T5.[LineNum] AND T5.LineSeq = 0
LEFT OUTER JOIN INV3 T6 ON T0.DocEntry = T6.DocEntry
group by T0.DocEntry,T3.[ChapterID],staType,LineNum,RelateType