I think that this should be sufficient:
SELECT
tra_item,
IsNull([Receipt],0)as Receipt,
IsNull([MRN_P], 0)as MRN_P,
IsNull([Issue], 0)as Issue,
IsNull([Rejection], 0) as Rejection,
IsNull([Transfer_P],0)as Transfer_P,
IsNull([Transfer_M],0)as Transfer_M,
IsNull([Receipt],0)+IsNull([MRN_P], 0)+IsNull([Issue], 0)+
IsNull([Rejection], 0)+IsNull([Transfer_P],0)+IsNull([Transfer_M],0) as Total
FROM
(
SELECT tra_item, tra_quantity, tra_type
FROM
tra_master
) as pvt
PIVOT (Sum(tra_quantity) FOR tra_type IN ([Receipt], [MRN_P], [Issue],
[Rejection], [Transfer_P], [Transfer_M])) as pvt
I can't work out what you were trying to do with your GROUP BY
and the SUM()
inside of your ISNULL()
s, since the PIVOT
already performs a SUM()
and it is performing an implicit GROUP BY
on all of the columns not mentioned in the PIVOT
(here, tra_item
).