cancel
Showing results for 
Search instead for 
Did you mean: 

Combining data from two years into a single query

Former Member
0 Kudos

Good Morning all,

With help from a member of the SAP community I was able to prepare a report which showed the current stock quantity, followed by monthly sales (6 months) for each item.

See the query below;

Declare @Year Numeric

Set @Year='2015'

SELECT T0.ItemCode, (T0.[OnHand] - T0.[IsCommited]) + T0.OnOrder AS 'Available',

                        sum(Case DATENAME(month,T2.DocDate) when 'June' then T1.Quantity   else 0 end) as 'June Qty',

                        sum(Case DATENAME(month,T2.DocDate) when 'July' then T1.Quantity   else 0 end) as 'July Qty',

                        sum(Case DATENAME(month,T2.DocDate) when 'August' then T1.Quantity   else 0 end) as 'AugQty',

                        sum(Case DATENAME(month,T2.DocDate) when 'September' then T1.Quantity   else 0 end) as 'Sept Qty',

                        sum(Case DATENAME(month,T2.DocDate) when 'October' then T1.Quantity   else 0 end) as 'Oct Qty',

                        sum(Case DATENAME(month,T2.DocDate) when 'November' then T1.Quantity   else 0 end) as 'Nov Qty',

                        sum(Case DATENAME(month,T2.DocDate) when 'December' then T1.Quantity   else 0 end) as 'Dec Qty'

 

FROM dbo.OITM  T0

      INNER JOIN INV1 T1 ON T0.ItemCode = T1.ItemCode

      INNER JOIN OINV T2 ON T1.DocEntry = T2.DocEntry

     

WHERE DATENAME(YEAR ,T1.DocDate )=@Year AND T0.ItmsGrpCod = '[%0]'

 

GROUP BY T0.ItemCode, T0.ItemName,T0.OnHand,T0.[IsCommited], T0.OnOrder

We now need to draw data for sales in 2016, however we need to keep the later months of 2015 on the report.

My question is whether there is any way of combining data from two separate years on one report?

Many thanks in advance

Tadhg

Accepted Solutions (0)

Answers (3)

Answers (3)

KennedyT21
Active Contributor
0 Kudos

Hi

If your thread is closed then close the thread with correct or helpful answers.

Cheers!!!

KennedyT21
Active Contributor
0 Kudos

Close the thread with correct and helpful answers!

Rgds

Kennedy

KennedyT21
Active Contributor
0 Kudos

Hi Tadhg...

Yes it is possible by using the Union SQl function.

Rgds

Kennedy