SELECT year(T1.Docdate) as [year] This is my attempt at starting this.. I only did till April ISNULL([Jan],0) as [Jan], ISNULL([Feb],0) as [Feb], ISNULL([Mar],0) as [Mar], ISNULL([Apr],0) as [Apr] FROM (Year, (T1.Doctotal) AS [BAL],year(T1.Docdate) as [year] FROM dbo.OCRD T0 LEFT JOIN dbo.OINV T1 ON T1.CardCode = T0.CardCode Where T0.[CardType] ='C' UNION SELECT Year, -(T1.Doctotal) AS [BAL],year(T1.Docdate) as [year] FROM dbo.OCRD T0 LEFT JOIN dbo.ORIN T1 ON T1.CardCode = T0.CardCode Where T0.[CardType] ='C' ) S PIVOT (SUM(S.[BAL]) FOR [year] IN ([Jan],[Feb],[March],[April])) P Order By Year
↧