Do use below SQL query but the issue that I have is that whenever there are 2 invoices on the same month with exactly the same amount it sum’s only one.
SELECT P.[CardCode],P.[CardName],
ISNULL([1],0) as [Jan],
ISNULL([2],0) as [Feb],
ISNULL([3],0) as [Mar],
ISNULL([4],0) as [Apr],
ISNULL([5],0) as [May],
ISNULL([6],0) as [Jun],
ISNULL([7],0) as [Jul],
ISNULL([8],0) as [Aug],
ISNULL([9],0) as [Sep],
ISNULL([10],0) as [Oct],
ISNULL([11],0) as [Nov],
ISNULL([12],0) as [Dec]
FROM (SELECT T0.CARDCODE, T0.CARDNAME, T0.GroupNum, T1.Doctotal AS [BAL],MONTH(T1.Docdate) as [month] FROM dbo.OCRD T0
LEFT JOIN dbo.OINV T1 ON T1.CardCode = T0.CardCode AND Year(T1.Docdate) = 2013
WHERE ( T1.CardCode ='200XXX') and (T1.Doctotal)<>0
union
SELECT T0.CARDCODE, T0.CARDNAME, T0.GroupNum,-(T1.Doctotal) AS [BAL],MONTH(T1.Docdate) as [month] FROM dbo.OCRD T0
LEFT JOIN dbo.ORIN T1 ON T1.CardCode = T0.CardCode AND Year(T1.Docdate) = 2013 WHERE (T0.CardCode ='200XXX')and (T1.Doctotal)<>0) S
PIVOT (SUM(S.[BAL]) FOR [month] IN
([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P