Hi,
Try this query:
SELECT P.CustCode, P.CustName, P.ItemNo, P.Name,
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 'Sept',
ISNULL([10],0) as 'Oct',
ISNULL([11],0) as 'Nov',
ISNULL([12],0) as 'Dec'
FROM
(SELECT T1.CardCode as CustCode, T1.CardName as CustName, (T0.ItemCode) as ItemNo, T0.Dscription as Name,
T0.Quantity as Qty,
MONTH(T1.docdate) as month
FROM dbo.dln1 T0 Inner Join ODLN T1 ON T0.DocEntry=T1.DocEntry
WHERE Year(T1.docdate) = 2013 and (T1.CardCode between 'cvet01' and 'cvet11' or T1.CardCode between 'CGEO01' and 'CGEO02')
UNION
SELECT T1.CardCode as CustCode, T1.CardName as CustName, (T0.ItemCode) as ItemNo, T0.Dscription as Name,
T0.Quantity as Qty,
MONTH(T1.docdate) as month
FROM dbo.rdn1 T0 Inner Join ORDN T1 ON T0.DocEntry=T1.DocEntry
WHERE Year(T1.docdate) = 2012) S
PIVOT (SUM(Qty) FOR month IN
([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
Group by P.CustCode, P.CustName, P.ItemNo, P.Name,[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]
Hope helpful.
Thanks & Regards,
Nagarajan