Hi
I have below code & i want Data to be displayed in Cross-Tab report like below.
Select T0.Date,Max(T0.cardcode) PartyCode,Max(T0.cardname) PartyName,
T1.ItemCode,Max(T1.Description) Dscription,Sum(T1.Total) Amount
from SaleHeader T0 inner join SalesDetail T1
on T0.doc = t1.doc
group by T1.ItemCode,T0.date
Total Sep'22 Aug'22 Jul'22 Jun'22 May'22 Apr'22
Item 1 12 2 10
Item 2 5 5
2 5 10

Deepak TewatiaRank #142 · 16K reputationPosted Dec 17, 2022, 2:14 PM EST
Hi Ramco,
you can use the PIVOT function in your query. The PIVOT function allows you to transform the rows of a table into columns, based on a pivot column and pivot values.
SELECT PartyCode, PartyName, ItemCode, Description, [Sep22], [Aug22], [Jul22], [Jun22], [May22], [Apr22], Total FROM ( SELECT T0.Date, T0.cardcode as PartyCode, T0.cardname as PartyName, T1.ItemCode, T1.Description, SUM(T1.Total) as Total FROM SaleHeader T0 INNER JOIN SalesDetail T1 ON T0.doc = t1.doc GROUP BY T1.ItemCode, T0.date, T0.cardcode, T0.cardname, T1.Description ) t PIVOT ( SUM(Total) FOR Date IN ( [Sep22], [Aug22], [Jul22], [Jun22], [May22], [Apr22] ) ) AS p