Territory Sales Query

Hello All -
Still looking for help with this query below.  The query is designed to show our monthly sales by territory.  However, it only shows those territories if there are sales for that month.  We would like the query to list the territory even if there are no sales.  Please help...thanks!
SELECT P.[STATE],
[1] as [Jan],
[2] as [Feb],
[3] as [Mar],
[4] as [Apr],
[5] as [May],
[6] as [Jun],
[7] as [Jul],
[8] as [Aug],
[9] as [Sep],
[10] as [Oct],
[11] as [Nov],
[12] as [Dec]
FROM (SELECT Left(T0.CardCode,2) as [State],
T0.DocTotal as [DocTotal],
MONTH(T0.docdate) as [month]
FROM dbo.oinv T0
WHERE Year(T0.docdate)=2011
UNION
SELECT Left(T0.CardCode,2) as [State],
-T0.DocTotal as [DocTotal],
MONTH(T0.docdate) as [month]
FROM dbo.orin T0
WHERE Year(T0.docdate)=2011 )  S
  PIVOT  (SUM(DocTotal) FOR [month] IN
([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
ORDER BY P.[State]

Your query seems to be getting the territory from the Card Code - is that correct? If that is the case, and you use the documnet tables you will only get those that exist in the tables.
If you want them all, you will need to draw the territory from the OCRD table & left join to the OINV & ORIN tables so all records will display

Similar Messages

  • 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

  • Sales Query

    Hi All,
    I have written a Query and need assistance in the logic.
    i have 4 Warehousea and each warehouse has its own Quanity and Sales Value. The Field displayed are Item Code, Item Desciption, Warehouse 1, Litres per Carton, Quantiy 1, Total Values 1, Warehouse 2, Litres per Carton, Quantiy 2, Total Values 2, Warehouse 3, Litres per Carton, Quantiy 3, Total Values 3, Warehouse 4, Litres per Carton, Quantiy 4, Total Values 4,
    The query is showing results but what ever the dates ranges i select the value are the same. I need help in the date range.
    The query is below
    SELECT DISTINCT T1.[ItemCode], T1.[Dscription],
    (select sum(T.[Quantity]) FROM INV1 T WHERE T.WhsCode = 'RT101' AND
    T.ItemCode = T1.ITEMCODE) AS NBI_QTY,
    (select avg(T.[U_Litres]) FROM OITM T WHERE T.ItemCode = T1.ITEMCODE )
    AS LTRS_PER_CTNS,
    (select avg(T.[LineTotal]) FROM INV1 T WHERE T.WhsCode = 'RT101' AND
    T.ItemCode = T1.ITEMCODE) AS NBI_SALES,
    (select sum(T.[Quantity]) FROM INV1 T WHERE T.WhsCode = 'RT101' AND
    T.ItemCode = T1.ITEMCODE) *
    (select avg(T.[U_Litres]) FROM OITM T WHERE T.ItemCode = T1.ITEMCODE )
    AS NBI_TOT_LTRS,
    (select sum(T.[Quantity]) FROM INV1 T WHERE T.WhsCode = 'RT102' AND
    T.ItemCode = T1.ITEMCODE) AS NKU_QTY,
    (select avg(T.[U_Litres]) FROM OITM T WHERE T.ItemCode = T1.ITEMCODE )
    AS LTRS_PER_CTNS,
    (select avg(T.[LineTotal]) FROM INV1 T WHERE T.WhsCode = 'RT102' AND
    T.ItemCode = T1.ITEMCODE) AS NKU_SALES,
    (select sum(T.[Quantity]) FROM INV1 T WHERE T.WhsCode = 'RT102' AND
    T.ItemCode = T1.ITEMCODE) *
    (select avg(T.[U_Litres]) FROM OITM T WHERE T.ItemCode = T1.ITEMCODE )
    AS NKU_TOT_LTRS,
    (select sum(T.[Quantity]) FROM INV1 T WHERE T.WhsCode = 'RT103' AND
    T.ItemCode = T1.ITEMCODE) AS KSM_QTY,
    (select avg(T.[U_Litres]) FROM OITM T WHERE T.ItemCode = T1.ITEMCODE )
    AS LTRS_PER_CTNS,
    (select avg(T.[LineTotal]) FROM INV1 T WHERE T.WhsCode = 'RT103' AND
    T.ItemCode = T1.ITEMCODE) AS KSM_SALES,
    (select sum(T.[Quantity]) FROM INV1 T WHERE T.WhsCode = 'RT103' AND
    T.ItemCode = T1.ITEMCODE) *
    (select avg(T.[U_Litres]) FROM OITM T WHERE T.ItemCode = T1.ITEMCODE )
    AS KSM_TOT_LTRS,
    (select sum(T.[Quantity]) FROM INV1 T WHERE T.WhsCode = 'RT104' AND
    T.ItemCode = T1.ITEMCODE) AS MSA_QTY,
    (select avg(T.[U_Litres]) FROM OITM T WHERE T.ItemCode = T1.ITEMCODE )
    AS LTRS_PER_CTNS,
    (select avg(T.[LineTotal]) FROM INV1 T WHERE T.WhsCode = 'RT104' AND
    T.ItemCode = T1.ITEMCODE) AS MSA_SALES,
    (select sum(T.[Quantity]) FROM INV1 T WHERE T.WhsCode = 'RT104' AND
    T.ItemCode = T1.ITEMCODE) *
    (select avg(T.[U_Litres]) FROM OITM T WHERE T.ItemCode = T1.ITEMCODE )
    AS MSA_TOT_LTRS
    FROM OINV T0 INNER JOIN INV1 T1
    ON T0.DocDate = T1.DocDate
    AND T1.[WhsCode] IN ('RT101','RT102','RT103','RT104')
    AND T0.DocDate >= '[%0]' AND  T0.DocDate <= '[%1]'
    GROUP BY T1.[ItemCode], T1.[Dscription]

    Dear Manish Chaturvedi,
    You can add another clause after where refering to the linestatus in RDR1.
    In RDR1 there is a field cold linestatus that will tell you if the line is closed (c) or open (o).
    If the query considers this field too it will show only the lines that are still open or partially open (e.g. originally you had a sales order for quantity 5 on row 1. You target only 3, but the row is still open).
    Regards,
    Marcella Rivi
    SAP Business One Forums Team

  • Pre sales query !

    Hi all,
    Guys this is not a technical query but i really didnt know whom or where to ask so i am putting this question here for all experts (whom i respect by heart)
    Sir how do you guys become expert in pre sales. I mean client can ask anything from anywhere. They can ask me on the fly that how many ports or modules are in 3900 series router ? they can ask me if stacking between 2960s and x is possible ? what about 3560x and 2960x and such. How am i supposed to remember all this stuff ?
    I know there are experts here who may know it all but what is the approach for getting such expertise ?
    Please guide me guys i will really appreciate your feedback on it.

    I suspect a lot of it is read off the Cisco Data sheets on the fly.
    That's right, you'll spend a lot of time reading these, so worth bookmarking the common ones in your browser.
    Cisco has a configurator within their CCW section. These is very useful, because it lists out all the possible part numbers associated with each product. You still need to do your research, but it's better than nothing. For example, it won't tell you that you only need one VPN license for a HA pair of ASAs. It won't tell you that you'll need a single 1m stack cable and for a large stack of 3750 switches.
    There is so much Cisco product information that you can never learn it all. I keep my notes updated and list out key points for the common products. MS OneNote might work well, although I still keep everything in a huge Word doc. If I learn anything new and important, then it gets added. Can be a pain, but it's a great reference. The only downside is that old info must be cross-checked, because things change. For example, features can sometimes drop down the IOS feature sets as time goes by.
    Take the most commonly sold products by your partner and build up some good notes on these first. Perhaps create some tables identifying key features, or use columns with tick boxes - i.e. Dual PSU?, stackable?, etc.
    Make sure you understand how the part numbers are constructed for your key products. For example, the part number for a common fixed-chassis switch like the 2960 or 3750 will tell you the number of switchports, type of switchports (RJ45/SPF), PoE (none/low/half/full), type of uplinks (RJ45/SFP/both), speed of uplinks (1/10GbE), type of IOS feature set etc etc
    Learn the key differences between the IOS feature sets for the most common products. This is important. You don't want any nasty post-sale surprises where the device won't perform a feature requested by the customer. It can be expensive.
    Cisco CCDA and CCDP exams will help with any design work.
    Cisco Live! 365 videos are good, so worth signing up www.ciscolive365.com
    Cisco Design Zone can be useful, but will depend how low-level your pre-sales role will be. Some roles are quite high level.
    Learn Visio (or similar) and create a base template to work from - i.e. get all your common icons and components ready, plus your subject box (i.e. title, customer, author, date, internal reference number etc)
    Template a nice long list of common caveats to add at the end of your proposal - i.e. customer to schedule network outage window, customer to supply fibre patch leads, customer to make available necessary rack space etc etc etc. Just take out the ones you don't need each time.
    Ask colleagues to vet your proposals whilst you're still learning.
    There's probably more, but that should help get you started.

  • Sales Query using SQ01

    I would like to create a query or maybe two queries that return the following.
    1. All Sales orders that have been invoiced in a particular time period. We must be able to show sales orders, net value and invoce number.
    2. All Sales orders that have not been invoiced but are setup to be delivered within the specified time period.
    Have been struggling with this one any help would be appreciated.
    Thank you

    Dear Clifton,
    In my opinion, the ABAP query is not the tool that meets your requirements for the following reasons:
    1. The tables to consider are too many :
        Query1  VBUK, VBUP, LIPS, VBFA, VBAK, VBAP, VBRK, VBRP
        Query2: VEPVG (Trigger Delivery), VBUK, VBUP, VBAK, VBAP
    2. You must also consider the customization of your system, because in some cases, the blocked orders (delivery block) and the unconfirmed orders (confirmed qty = 0 in availability check) not appear as entries in VEPVG table.
    3. Join of all these tables using ABAP Query or quick viewer, has low performance, in other words kneel the system.
    I think that you should seriously consider the possibility of developing 2 new ABAP programs ($$$) without underestimating the aspect of performance which is crucial in this case.
    Thanks.
    Kind regards.
    Andrea

  • Question On YTD Total Sales Query

    Hello,
    We use this query below to see YTD sales for each of our BP Customers:
    SELECT T0.CardCode 'Acct #', T0.CardName Company, T0.Address
    ' Address', T0.City ' City', T0.State1 State, T0.ZipCode
    'Billing Zip', T0.Phone1 Phone, T0.Balance ' Balance',
    T1.SlpName 'Sales Rep',
    T2.PymntGroup Terms, T3.GroupName 'Group', ((SELECT ISNULL(SUM(INV1.LINETOTAL),0)
    FROM INV1 INNER JOIN OINV ON INV1.DocEntry = OINV.DocEntry
    WHERE OINV.CardCode = T0.CardCode AND Year(INV1.DocDate) = Year(GetDate()))-(SELECT ISNULL(SUM(RIN1.LINETOTAL),0)
    FROM RIN1 INNER JOIN ORIN ON RIN1.DocEntry = ORIN.DocEntry
    WHERE ORIN.CardCode = T0.CardCode AND Year(RIN1.DocDate) = Year(GetDate()))) [YTD Sales]
    FROM OCRD T0
    LEFT JOIN OSLP T1 ON T1.SlpCode = T0.SlpCode
    LEFT JOIN OCTG T2 ON T2.GroupNum = T0.GroupNum
    LEFT JOIN OCRG T3 ON T3.GroupCode = T0.GroupCode
    WHERE T0.CardType = 'C'
    We use this query below to see daily Invoice and Credit Memo postings for a selected period:
    SELECT 'INVOICE' as "Doc Type", T0.DOCNUM as "Doc Number", T0.CARDCODE as "Customer Code", T0.CARDNAME as "Customer Name", T0.DOCDATE as "Posting Date", T0.NUMATCARD as "Customer Ref #", T0.DocDueDate, T0.DocTotal
    FROM [dbo].[OINV] T0 WHERE T0.DOCDATE BETWEEN '[%0]' And '[%1]'
    UNION ALL
    SELECT 'CREDIT MEMO', T0.DOCNUM,T0.CARDCODE, T0.CARDNAME, T0.DOCDATE, T0.NUMATCARD, T0.DocDueDate, -1*T0.DocTotal
    FROM [dbo].[ORIN] T0 WHERE T0.DOCDATE BETWEEN '[%0]' And '[%1]'
    My question is -- shouldn't the sum of the YTD column in the 1st Query be the same as the sum of the Doc Total column in the 2nd Query (given that all dates are selected in the 2nd Query)? 
    This doesn't appear to be the case and I was wondering why?
    Thanks,
    Mike

    Mike,
    The DocTotal may contain Freight and Handling expenses, While the first query only taken the SUM of the line total of the Items.
    Thats why they may be different.
    Suda

  • 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

  • Internet sales query

    Hello Friends,
    Can anybody give me the list of J2EE components, which needs to be deployed for ISA B2B Scenario and User Administration?
    Thanks in advance.
    Best Regards
    Kushal

    Internet Sales B2B J2EE components are packaged and shipped by SAP as .EAR file.
    .EAR are one of kind of file that can be deployed using the SDM.
    If you want to see the B2B J2EE components, use NWDS(NetWeaver Developer Studio). or If you have deployed the B2B EAR, then you can see the Directory Structure in the Server (D:\usr\sap\JD<i>\JC<ii>\j2ee\cluster\server<i>\apps\sap.com\b2b)
    Same applies for USerAdmin !!!
    Thanks
    Jack
    Allot points if my Post helps !!!

  • 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

  • Pre-sales query regarding: 59-442243

    I am intending to buy a Lenovo notebook in a day or two. But have a few questions in mind which I am not getting answer to anywhere. Would anyone be kind enough to please clear these queries of mine regarding your notebook model 59-442243:
    1. Is the screen matte(anti-glare) or glossy?
    2. Does it have 2 ram slots to support 16 GB RAM?
    3. Whats the difference between Lenovo 59-442243 & 59-422412 ? Both show same specs.
    Thanks

    akb wrote:
    I am intending to buy a Lenovo notebook in a day or two. But have a few questions in mind which I am not getting answer to anywhere. Would anyone be kind enough to please clear these queries of mine regarding your notebook model 59-442243:
    1. Is the screen matte(anti-glare) or glossy?
    2. Does it have 2 ram slots to support 16 GB RAM?
    3. Whats the difference between Lenovo 59-442243 & 59-422412 ? Both show same specs.
    Thanks
    Both are G50-70 notebooks, the first 59-442243 appears to lack WiFi (Wireless Networking) but has a 1TB hard disk drive.  The second 59-422412 has a 802.11b/g/n card, but a smaller 500GB hard drive.
    Both appear to have the non-glare screen option and have two memory slots with support for upto 16GB of memory according to the G50 product specifications.
    I would advise to contact the seller you obtained the model numbers from and ask for detailed specifications as they may have altered the units prior to makeing them available for purchase.
    Cheers.

  • Pre-Sales query for Voice product

    Hi Team,
    We have a customer who wants to go for VOIP. He is currently running an Alcatel PABX
    The requirements are
    1) Users - 200
    2) Free Calls between HQ and Branch
    3) Voice Mails to be Delievred in Users Inbox
    4) Send Fax from the Users machine.
    Can I achieve the above using a CME . If yes then which model and IOS should I opt for? What should the PVDM requirement be?

    Yes, you can do that with CME.
    For an accurate design, you should get in touch with a reputable consultant, or UC certified Cisco partner.
    The alternative is that you read and stufy the avaialble documentation on cisco.com. However doing so you risk to wast much time, and not get good results.

  • Territory information for sales Order

    Hello,
    We are trying to find territory/sales person information for an Order. When we entered the order then we do not enter sales person name, so now we are trying to find territory/sales person information
    Based on Territory setup, like sales order customer name or zip code etc…is there any public api which can be used to find this information. We are doing kind of reverse engineering…like find the sales rep information for an order …
    Thanks
    Deepak

    793318 wrote:
    Hello,
    We are trying to find territory/sales person information for an Order. When we entered the order then we do not enter sales person name, so now we are trying to find territory/sales person information
    Based on Territory setup, like sales order customer name or zip code etc…is there any public api which can be used to find this information. We are doing kind of reverse engineering…like find the sales rep information for an order …
    Thanks
    DeepakI'm not sure about the api's but here is how you can get through it..
    Since you've the order information, you know who the customer is. Get the party information of the customer from hz_parties.
    Now, it is going to be little tricky to find out the right sales rep based on how the territories and how the upstream processes is handled - let us go one by one -
    I'm assuming this is some kind of conversion activity and you are trying to find out who the sales rep was?
    Alright, If this order was generated from a quote you always have a reference. If it does not have a quote, does it tie back to an opportunity/lead? if yes, use the party information identified in the earlier step - identify how many opportunities are there? if it is more than, see if the right product is captured on the opportunity...if No, then it is tricky and you have to by creation date or atleast by last_updated_date. And, the owner on the opportunity or lead would be your sales rep.
    Now, if you dont have an opportunity/lead....how am I going to find out.......
    Again, you hve the party information, check who is on the sales team. if there is more than one sales rep, you have to see where these sales reps fall into and in which territory........
    In simple words - if you have more than one sales rep who can work on a given lead or opportunity and if you dont have any other custom attributes identified at the territory level, it would be tough to identify the right sales rep....
    hey, by the way - if you have commissions and if you have paid the commissions, you can find out the right sales rep......that is down stream!!!!
    HTH

  • Is there a way to create a plan guide for this query?

    How can i create a plan guide for this query,suppose i can't change the query text:
    USE AdventureWorks2008R2;
    GO
    SET NOCOUNT ON;
    GO
    -- query plan statement starts
    DECLARE @Group nvarchar(50), @Sales money;
    SET @Group = N'North America';
    SET @Sales = 2000000;
    SET NOCOUNT OFF;
    SELECT FirstName, LastName, SalesYTD
    FROM Sales.vSalesPerson
    WHERE TerritoryGroup = @Group and SalesYTD >= @Sales;
    -- query plan statement ends
    AdventureWorks2008R2's parameterization option is simple, i want this type of query can reuse plan:
    DECLARE @Group nvarchar(50), @Sales money;
    SET @Group = N'Other Country';
    SET @Sales = 88;
    SET NOCOUNT OFF;
    SELECT FirstName, LastName, SalesYTD
    FROM Sales.vSalesPerson
    WHERE TerritoryGroup = @Group and SalesYTD >= @Sales;
    I tried many times ,but it didn't work:
    declare @xml nvarchar(max) -- the plan i want to reuse
    set @xml = (select cast (query_plan as nvarchar(max)) 
    from sys.dm_exec_query_plan (0x060006001464570B405D92620200000001000000000000000000000000000000000000000000000000000000))
    -- create plan guide 
    exec sp_create_plan_guide 
    @name ='Test'
    ,@stmt=N'SELECT FirstName, LastName, SalesYTD
    FROM Sales.vSalesPerson
    WHERE TerritoryGroup = @Group and SalesYTD >= @Sales;'
    ,@type =N'sql'
    ,@params =N'@Group nvarchar(50), @Sales money'
    ,@hints = @xml;
    Thanks.

    I guess you don't wanna fire these queries "adhoc" but prepared instead to reuse the plan:
    exec sp_executesql N'SELECT FirstName, LastName, SalesYTD FROM Sales.vSalesPerson WHERE TerritoryGroup = @Group and SalesYTD >= @Sales',
    N'@Group nvarchar(50), @Sales money', N'Other Country',88
    exec sp_executesql N'SELECT FirstName, LastName, SalesYTD FROM Sales.vSalesPerson WHERE TerritoryGroup = @Group and SalesYTD >= @Sales',
    N'@Group nvarchar(50), @Sales money', N'North America',2000000
    Bodo Michael Danitz - MCT, MCITP - free consultant - performance specialist - www.sql-server.de

  • Spem fields are missing In the Query

    Hi this is a FI-Sales Query , under Material Group consists Bags,Caps,wallets ete like these lot of fields but in the query i am not getting all the field. in the query designer every thing is there some fields are not coming like Tie etc,But remeber this is Production Issue.I think u r clear with the issue.
    Any Help

    Hi kumar
    I guess what u are talking about is a values in the infoobject material group are not populating into the query.
    The problem is accordig to me is that the master  data for the material Group is deleted so thats the reason u can t find material group values in the query.
    If i have not understood the problem then restate the problem again in other words.
    If this solves ur problem then kindly assingn the points.

  • YTD Query and web template

    Hi,
    i have created a query on YTD sales query and comparison with the previous year. i have created a structure using 0calmonth2 info object and restricted it for each month starting from July to June. In the key figures i have used sales values key figure and restricted one with variable  0I_PRFYE for all fiscal year periods of previous year and for the current year i used a value range from 001.YYYY to the current fiscal year period. where YYYY is the same fiscal year as in current fiscal year period.
    After executing the query for sales values in previous year i have a value against every fiscal year period  in the previous year. For the current year i have the value only for the first month as we are in the first month.
    example:
                           jul  aug  sep  oct  nov  dec  jan  feb  mar  apr  may  jun
    Current year   17     0      0     0     0     0     0    0      0     0      0     0 
    Previous Year12   13    18   34    23   67    20  10    83   34     25   27
    When i creating a line chart based on this data, for the current year the line drops from jul to aug and continues to be zero through out the year. what i am expecting is it should not drop to zero as we have not yet come to aug in the current year. What i am expecting is that the line should be showing as a dot in the current month jun, when the current fiscal year period is aug i will have some value in the aug so the chart should show a line from jul to aug.
    I tried to change the display of zero's as blank & even tried replacing zeros with some characters but could not achieve the desired result.
    can some body help me achieve this. Correct responses will be awarded appropriately.
    Regards,
    Ravi.

    Hi,
    The line chart shows the two series one for previous year and one for current year.
    the issue is with current year. as the value for aug is blank the line chart drops to zero on the y axis. What i want to achieve is that as i am not yet in aug and my current fiscal yera period is jul i dont want the line to drop to zero. in this case i want it to be just a dot on y axis depending on the value. Once my current fiscal year period is aug i want a line from jul to aug only. In the current senario if my current fiscal year period is aug i will have the line from jul to aug but then drops to zero on y axis for sep. I dont want that to happen.
    Hope iyou understand what i am trying to explain.
    Thanks for your reply.
    Ravi.

Maybe you are looking for

  • Change trim size in pdf?

    Hi, I'm very new to working with pdf, so any help is very appreciated!  I have an 8x11 pdf document I need to turn into 6x9.  No matter how I set the printing, the file still reads 8x11, and still prints at 8x11.  How to I change the trim size?  If I

  • Itunes on external drive

    I have screwed up my iTunes library. I have a ton of movies and music on a drive and I cannot figure out how to make it my iTunes destination. I have no problem accessing everything I have purchased - its all in the cloud. How can I fix this I will s

  • "call to a possibly undefined method" error.

    I've been working my way through the tutorials in Gary Rosenzweig's "Flash Game University" book. Working on the "paddle ball" game tutorial, I changed the name of the file from "PaddleBall.fla" to "MyPaddleBall.fla", and changed the name of the .as

  • Help with AQ and Java

    I am brand new to using AQ and I'm having a problem getting the JMS Message Listener to recognize there are messages on the queue. Can anyone point me in the right direction? I've been looking at all of the stuff in the AQ Developer's Guide and some

  • How do I get Internet on my iPod Touch?

    How do I connect to youtube and the internet on my ipod touch?