Monthly Qty Sales Query

Ran this Query below and it pulled up redundant data for Jan and June?!  Anyone know how to correct?  Should be just Jan 2010.
Thanks,
Mike
SELECT T0.ITEMCODE,
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 1 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JAN QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 2 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'FEB QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 3 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAR QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 4 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'APR QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 5 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAY QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 1 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUN QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 7 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUL QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 8 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'AUG QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 9 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'SEP QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 10 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'OCT QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 11 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'NOV QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 12 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'DEC QTY'
FROM [dbo].[OITM] T0
LEFT JOIN [dbo].[INV1] T1 ON T1.ItemCode = T0.ItemCode
WHERE T0.SellItem = 'Y'
GROUP BY T0.ItemCode,YEAR(T1.DOCDATE) HAVING  YEAR(T1.DOCDATE) = YEAR(GETDATE())
ORDER BY T0. ITEMCODE

Mike,
I notice that for the Month of June the MONTH(T1.DOCDATE) = 1 is pointing to Jan which I corrected to 6 in the query below.
SELECT T0.ITEMCODE,
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 1 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JAN QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 2 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'FEB QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 3 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAR QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 4 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'APR QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 5 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAY QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 6 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUN QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 7 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUL QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 8 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'AUG QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 9 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'SEP QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 10 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'OCT QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 11 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'NOV QTY',
(SELECT SUM(T1.QUANTITY) FROM INV1 T1 with (NOLOCK)
WHERE MONTH(T1.DOCDATE) = 12 AND T1.ITEMCODE =
T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'DEC QTY'
FROM dbo.OITM T0
LEFT JOIN dbo.INV1 T1 ON T1.ItemCode = T0.ItemCode
WHERE T0.SellItem = 'Y'
GROUP BY T0.ItemCode, YEAR(T1.DOCDATE) HAVING YEAR(T1.DOCDATE) = YEAR(GETDATE())
ORDER BY T0. ITEMCODE
Suda

Similar Messages

  • Qty sales & month

    Dear Forums,
    If i want to get this report for This month so far ;
    item code, item description, DocDate,stock on hand, Qty sales, Turn over, Turn over days
    eg . April 20,
    542514 / MILK/ 11-05-09 / 40 / 10 / 2.66666 / 80 / 20 / 30
    542518/ SOAP/ 11-05-09 / 40/ 10 / 2.66666 / 80 / 20 / 30
    can any one show me the query? thanks
    Edited by: rachelhel on Apr 22, 2009 7:48 AM
    Edited by: rachelhel on Apr 22, 2009 10:38 AM

    Hi ,
    Please try this .....
    SET ARITHABORT OFF SET ANSI_WARNINGS OFF
    SELECT T0.ItemCode, T0.Dscription,T1.OnHand, convert(varchar,SUM(T0.BaseQty*T1.NumInSale)) AS 'Qty Sales',DAY(GetDate()) as 'Days',
    Case WHEN Month(GetDate()) in (1,3,5,7,8,10,12) THEN 31 WHEN Month(GetDate()) in (2,4,6,9,11) THEN 30 ELSE 28 END AS 'Total days'
    ,convert (varchar,(t1.onhand/(SUM(T0.BaseQty*T1.NumInSale)/DAY(GetDate())* Case WHEN Month(GetDate()) in (1,3,5,7,8,10,12) THEN 31 WHEN Month(GetDate()) in (2,4,6,9,11) THEN 30 ELSE 28 END)))AS 'TURN OVER IN MONTH'
    FROM DBO.INV1 T0 INNER JOIN DBO.OITM T1 ON T0.ItemCode = T1.ItemCode
    WHERE Month(T0.DocDate) = Month(GetDate()) AND Year(T0.DocDate) = Year(GetDate())
    GROUP BY T0.ItemCode,T0.Dscription,T1.OnHand
    union
    SELECT T1.ItemCode, T1.itemname,T1.OnHand, '' AS 'Qty Sales',DAY(GetDate()) as 'Days',
    Case WHEN Month(GetDate()) in (1,3,5,7,8,10,12) THEN 31 WHEN Month(GetDate()) in (2,4,6,9,11) THEN 30 ELSE 28 END AS 'Total days'
    ,'No Sales' AS 'TURN OVER IN MONTH'
    FROM DBO.OITM T1
    WHERE T1.ITEMCODE NOT IN (SELECT ISNULL(ITEMCODE,0) FROM INV1)
    GROUP BY T1.ItemCode,T1.itemname,T1.OnHand
    ORDER BY 1

  • "Qty Sales Result not Same"

    hai all Expert..,
    I have a problem with my Query .., may have that can help me.
    I create a Query for Qty sales, after I was working Excecute
    but after I check the results one by one with the sales results
    of the analysis appeared to have all that is not the same as the results of the analysis in sales
    SELECT T0.ItemCode, T0.Dscription,T1.OnHand,T0.DocDate,T0.ActDelDate, SUM(T0.BaseQty * T1.NumInSale) AS 'Qty Sales' ,DAY(GetDate()) as 'Days',
    Case WHEN Month(GetDate()) in (1,3,5,7,8,10,12) THEN 31 WHEN Month(GetDate()) in (2,4,6,9,11) THEN 30 ELSE 28 END AS 'Total days'
    FROM DBO.INV1 T0 INNER JOIN DBO.OITM T1 ON T0.ItemCode = T1.ItemCode
    WHERE
    T0.ItemCode  ='01000006' and
    (Month(T0.DocDate) = Month(GetDate())-1)  AND Year(T0.DocDate) = Year(GetDate()) and
    (T0.BaseQty * T1.NumInSale)>0
    GROUP BY T0.ItemCode,T0.Dscription,T1.OnHand,T0.DocDate,T0.ActDelDate
    ORDER BY T0.ItemCode,T0.DocDate
    Thanks...

    Try This
    SELECT T0.ItemCode, T0.Dscription,T1.OnHand,T0.DocDate,T0.ActDelDate, SUM((T0.Quantity * T1.NumInSale)-T1.OPENQTY) AS 'Qty Sales'
    ,DAY(GetDate()) as 'Days',
    Case WHEN Month(GetDate()) in (1,3,5,7,8,10,12) THEN 31 WHEN Month(GetDate()) in (2,4,6,9,11) THEN 30 ELSE 28 END AS 'Total days'
    FROM DBO.INV1 T0 INNER JOIN DBO.OITM T1 ON T0.ItemCode = T1.ItemCode
    WHERE
    T0.ItemCode ='01000006' and
    (Month(T0.DocDate) = Month(GetDate())-1) AND Year(T0.DocDate) = Year(GetDate()) and
    (T0.BaseQty * T1.NumInSale)>0
    GROUP BY T0.ItemCode,T0.Dscription,T1.OnHand,T0.DocDate,T0.ActDelDate
    ORDER BY T0.ItemCode,T0.DocDate

  • Customers without sales in last 6 months by sales group

    How would you get the customers that had not placed an order in the last six months by sales group?
    I was looking if in MCSI I could find something but no luck, I guess I will have to make a query on SQVI
    Regards,
    Carlos

    You need to create a Z-Report or manually download data into excel and compare.
    You need to sort out all customers based on sales group from table KNVV. Then check against orders created against those sales groups in last 6 months - the difference is te result.
    There are two points to be taken care of -
    1. All customers which was created in last 6 months but have not done any business - should be excluded from result
    2. If sales group is put/changed manually in transaction (i.e. customer and sales order sales groupd are different) then the logic will not work properly - Sales group wise.
    I had faced these problems in a similiar report, so just informing.
    Thanks

  • Monthly wise sales report

    hai,
         i m working on sales report where in i need to get month wise sales of the products and the related cost incured to company by the sales in the matrix form as shown below  can u help me in which way can i get this monthly report
              march     april     may   june    july......feb
    mtrl    25            30         0       19      23   ........(mtrl quantity)
    cost   30000     15000      0      45000  ..........(amt in rs)
    where in the above i m able to get yearly sales in one column (i.e i m able to show for one particular customer total sales in one column) but i m unable to split sales monthly and unable to show in a report so how can i able to sow in this matrix form

    Dear Raj,
    Please find the code for monthly wise report in PA0001 Table for calculation of Administrator time Recording.
    http://scn.sap.com/message/14216250#14216250

  • Monthly wise Sales report - Help me

    Dear SDN mates
    Is there any standard reports for Monthly wise sales report ...the SAP1 , SAP2 reports were not helpful....Does this can be solved by standard reports or it needs to be customized????
    kindly help me?

    hi,
    check VC05 transaction.

  • Customer  month wise sales

    Dear All
    Any Standared Report Available Customer  month wise sales available?
    Thanks and Regards
    Suresh

    Hi,
    To determine which info blocks should be displayed in the sales summary and how they should be combined in views, see the IMG under Sales and Distribution - Sales Support (CAS) - Sales Summary.
    If you want the sales summary to appear differently to specific users, you can assign views to users in this Customizing step.
    If you do not do this, the system displays the standard reporting view.
    regards,
    Siddharth.

  • Customer and month wise sales

    Dear All
        Which Table Stored Customer and month wise sales values?
    Thanks and Regards
    Suresh

    Hi
    Table VBRK Will help you.
    Assign points if you find the solution with this
    Regards

  • Currency conversion by Calendar month in the query?

    Hellow...
    Users want DB currencies when executing query at first. And then want to change currency conversion by Calendar month in the query, if navigating by target currency. Tried as created TEST Currency Translation Key. Database currency is different currencies.
    Appreciate your help.
    Don.

    Hi,
    Create Currency conversion type using Trans: RRC1.
    1.Specify your Exchange rate type.                     
    2.Dynamic Exchange rate type
    3.Source curency from data rec.
    4.Fixed currency say USD.
    5.Select Variable Time reference "Start Month" and Special Info Object - 0calmonth
    Secondly In the key figure field to be converted in the query,   select properties - select the currency conversion key name .
    Thanks,
    Nagesh
    Sony Singapore

  • COPA from Billing seperate sales rev qty & sales return qty

    Dear Experts,
    If we need to seperate sales rev qty & sales return qty, how do we send sales rev qty & sales return qty by billing type?
    Thanks in advance.

    HI,
    I assume you want to post the sales rev. qty / sales return qty. You can use enhancement COPA005 (include ZXKKEU08) to move actual values/quantities to other value/quantity fields if you have a rule for that.
    I guess you can use the SD document category which is assigned to every billing type to differentiate between sales postings and sales return postings. This is more stable than focussing on the billing type itself (where a new one is created easily but nevertheless it must be assigned to an existing SD document category).
    best regards, Christian

  • Query for Opening Stock + Purchase Qty + Sales Qty

    Hi ,
    Can anyboday help me by how to develop a query for the following requirement. If any custom query is available please provide me .We are working on SBO 2007B PL 8. The required report structure is 
        ItemNo ***OpeningStock**** Purchase ********* Sales****
    (Batchwise)** Qty*** Value ****Qty** Value ***Qty***Value
    Thanks & Regards
    Srini

    Hi Srini,
    I found this on the forum, see if it helps you;
    select b.Itemcode,b.Item_Description,b.UOM, b.rate as Rate,b.Opening_Stock,b.Receipt,b.Issue, b.Material_Revalue,b.Closing_Stock,b.Closing_Value from (select *,(case closing_stock when 0 then 0 else(Closing_Value/Closing_Stock)end) as Rate from( SELECT T0.Itemcode as 'Itemcode' ,min(T0.Dscription) as 'Item_Description', max(T1.InvntryUom) as UOM, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<'[%0]' and O1.transtype in (58,59,20,16,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<'[%0]' and O1.transtype in (58,21,19,60,15,67,-2,13)),0)+ (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.transtype in (-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.transtype in (-2)),0)))as Opening_Stock, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (20,18)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (67)),0) + isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.inqty>0 and O1.transtype in (58,59,16,14)),0)) as Receipt, (isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (13,15)),0) + isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (67)),0)+ isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate>='[%0]' and O1.docdate<='[%1]' and O1.outqty>0 and O1.transtype in (58,60,21,19)),0)) as Issue, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (162)),0) as Material_Revalue, (isnull((Select sum(isnull(inqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,59,20,16,14,19,67,-2)),0) - isnull((Select sum(isnull(outqty,0)) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,21,19,60,15,67,-2,13)),0))as Closing_Stock, isnull((select sum(Transvalue) from OINM O1 where O1.itemcode=T1.itemcode and O1.docdate<='[%1]' and O1.transtype in (58,18,-2,67,59,20,16,14,15,13,21,19,60,69,162)),0) as Closing_Value FROM OINM T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITW T2 ON T1.ItemCode = T2.ItemCode INNER JOIN OITB B1 ON T1.ItmsGrpCod=B1.ItmsGrpCod where ((B1.ItmsGrpNam>='[%2]' and B1.ItmsGrpNam<='[%3]') or ('[%2]'='' and '[%3]'='')) GROUP BY T1.itemcode,T0.Itemcode )a Where (a.Opening_Stock + a.Receipt + a.Issue + a.Material_Revalue + a.Closing_Stock + a.Closing_Value) <> 0 )b 
    Thanks,
    Joseph

  • Help With Monthly Sales Query

    Hello All -
    We use the below Query to find monthly sales for each of our stock units.  However, it only provides the current year -- so for 2010, all our 2009 data is gone and the query just shows Jan 2010.
    Is there any way to adjust this Query so that we can select the year we want to see?
    Thanks!
    Mike
    SELECT T0.ITEMCODE,
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 1 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JAN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 2 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'FEB Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 3 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 4 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'APR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 5 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAY Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 6 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 7 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUL Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 8 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'AUG Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 9 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'SEP Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 10 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'OCT Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 11 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'NOV Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 12 AND T1.ITEMCODE
    = T0.ITEMCODE AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'DEC Amt'
    FROM dbo.OITM T0
    LEFT JOIN dbo.INV1 T1 ON T1.ItemCode = T0.ItemCode
    WHERE T0.SellItem = 'Y'
    GROUP BY T0.ItemCode,YEAR(T1.DOCDATE) HAVING YEAR(T1.DOCDATE) = YEAR(GETDATE())
    ORDER BY T0. ITEMCODE

    /*Hello there!!
    you should try this code*/
    SELECT T0.ITEMCODE, (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 1
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'JAN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 2
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'FEB Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 3
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'MAR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 4
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'APR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 5
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'MAY Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 6
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'JUN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 7
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'JUL Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 8
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'AUG Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 9
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'SEP Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 10
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'OCT Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 11
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'NOV Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 12
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1)) AS 'DEC Amt'
    FROM dbo.OITM T0 LEFT JOIN dbo.INV1 T1 ON T1.ItemCode = T0.ItemCode WHERE T0.SellItem = 'Y'
    GROUP BY T0.ItemCode,YEAR(T1.DOCDATE) HAVING YEAR(T1.DOCDATE) = (YEAR(GETDATE())-1) ORDER BY T0. ITEMCODE
    thou i suggest that its more practical for you to use a variable to enter the year, for example like this.
    declare @year as char(4)
    set @year = '2009'
    SELECT T0.ITEMCODE, (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 1
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'JAN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 2
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'FEB Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 3
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'MAR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 4
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'APR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 5
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'MAY Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 6
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'JUN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 7
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'JUL Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 8
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'AUG Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 9
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'SEP Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 10
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'OCT Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 11
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'NOV Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with (NOLOCK) WHERE MONTH(T1.DOCDATE) = 12
    AND T1.ITEMCODE = T0.ITEMCODE AND YEAR(T1.DOCDATE) = @year) AS 'DEC Amt'
    FROM dbo.OITM T0 LEFT JOIN dbo.INV1 T1 ON T1.ItemCode = T0.ItemCode WHERE T0.SellItem = 'Y'
    GROUP BY T0.ItemCode,YEAR(T1.DOCDATE) HAVING YEAR(T1.DOCDATE) = @year ORDER BY T0. ITEMCODE

  • Help with query: monthly accumulated sales by month

    Hi,
    i need to build a query that shows two key figures:
    KF1) Sales accumalated on last 60 months.
    KF2) Sales for actual month.
    i know i can solve this using selections, the problem is my client needs it on columns for each month selected
    from a range. For example:
    Selecting months 01.2009 - 04.2009:
    01.2009 | 02.2009 | 03.2009 | 04.2009
    KF1|KF2 | KF1|KF2 | KF1|KF2 | KF1|KF2
    KF2 appears by default, but is it possible to show KF1 using selections ?

    Hola Juan Pablo.
    Here the main problem I see is the possibility of select a range for the 0CALMONTH. First of all try to speak to your customer to agree the possibility of select in the variables the "Ending/Last" 0CALMONTH. If you can achieve this the rest is more  o less easy.
    You have to define an structure o several RKF and from 0CALMONTH you make a set of variables (post-popop) to restric them:
    RKF_1M_01  (Selected Month)
    RKF_1M_60  (Selected Month) - (offset - 60)
    RKF_2M_01  (Selected Month -1 )
    RKF_2M_60  (Selected Month -1 ) - (offset - 60)
    RKF_3M_01  (Selected Month -2 )
    RKF_3M_60  (Selected Month -2 ) - (offset - 60)
    RKF_4M_01  (Selected Month -3 )
    RKF_4M_60  (Selected Month -3 ) - (offset - 60)
    I've made something similar for Balance Sheet
    Hope it helps you.
    Regards

  • Item Query by onhand/QTY Sold in last week/month/QTY

    I am trying to create a query showing items that are in a particular warehouse and then how many of that item has been sold over the last week/month/quarter.
    I have got the following query started,but i am unsure to group can anyone help with this
    SELECT T0.[ItemCode], T0.[ItemName],T1.[OnHand],   T0.[IsCommited],  T0.[MaxLevel], T0.[MinLevel], T2.[Quantity]
    FROM [dbo].[OITM]  T0 INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode INNER JOIN INV1 T2 ON T0.ItemCode = T2.ItemCode
    WHERE T1.[WhsCode] = '01'

    I am trying to create a query showing items that are in a particular warehouse and then how many of that item has been sold over the last week/month/quarter.
    I have got the following query started,but i am unsure to group can anyone help with this
    SELECT T0.[ItemCode], T0.[ItemName],T1.[OnHand],   T0.[IsCommited],  T0.[MaxLevel], T0.[MinLevel], T2.[Quantity]
    FROM [dbo].[OITM]  T0 INNER JOIN OITW T1 ON T0.ItemCode = T1.ItemCode INNER JOIN INV1 T2 ON T0.ItemCode = T2.ItemCode
    WHERE T1.[WhsCode] = '01'

  • Sum sales query last 6 months

    Hi people......
    Using docdate and sum(quantity) how can i sum the last 6 months from today.??
    select itemcode, sum(quantity) FROM oinv, inv1, oitm, oitb.......   WHERE getdate()  ?????
    I hope explain correctly....

    Hi,
    Better use: DateDiff(DD,T0.DocDate,getdate()) >=  180
    Thanks,
    Gordon

Maybe you are looking for

  • Dvds can no longer be read on MacPro

    DVD drive used to play Movie DVDs fine  but recently stopped - on inserting a DVD now, machine clicks for a while then ejects the DVD. Inserting a CD (music) or data is fine - disc is accepted and available for access. Any ideas why just the DVD reje

  • It was working and now it's not

    I was listening to music throughout the house all day so iTunes was sending to the Apple TV for the theater speakers. I turned everything off, did some stuff and then decided to listen to some more music while I worked. I turned on everything includi

  • Camcorder no longer supported by iMovie. What do I do?

    I see that the Canon Legria HF S20 is not supported any more by iMovie. I'm not going to be changing this camcorder soon, it's still really good! I now have hours of video on the camcorder that I can't watch or save on my Mac.  Are there any ways aro

  • Grouping Videos as different "Kinds"

    Hello. I recently purchase a White 30GB 5G Video iPod. I'm relatively impressed. A few bugs, but that's understandable for something so new and so young. I was wondering, on my iPod there are only two options to sort each Video. Music Videos, or Movi

  • Post processing agent in partner profile

    Hi Inbound idoc fails. The partner profile has a user (US) in the post processing:permitted agent, both on the actual partner (LS) and on the inbound message type. I would expect to see the error in the inbox of the business workplace, but I see noth