Sales By State Query

Hello All -
We would like to develop a query that shows us monthly sales by each US state and OUS locations.  For example, on the left most column, we would have each location.  Then subsequent columns to the right of that would have sales for each location in Jan, Feb, March, etc.
Can anyone help with this?
Thanks,
Mike

I tried first three months below:
SELECT T0.State1 AS 'Bill-to State', (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK) INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
WHERE MONTH(T1.DOCDATE) = 1 AND T2.State1 = T0.State1
AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JAN Amt', (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK) INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
WHERE MONTH(T1.DOCDATE) = 2 AND T2.State1 = T0.State1
AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'FEB Amt', (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK) INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
WHERE MONTH(T1.DOCDATE) = 3 AND T2.State1 = T0.State1
AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAR Amt',
FROM dbo.OCRD T0 LEFT JOIN dbo.OINV T1 ON T1.CardCode = T0.CardCode
GROUP BY T0.State1
ORDER BY T0.State1
But did not get any data -- not sure what I am doing wrong?!
Mike

Similar Messages

  • Sales by State report

    Hi
    Wondering if anyone can help me with a query to extract sales information from B1. I'm trying to build a report to show all sales by state in SAP Business One. I have come across this code and while it is close to what I need it doesn't go the whole way.
    Along with the sales from each state I need to include the wareshouses that stock was sold from. I also need to sum each column (I know that you can press Ctrl and Click to get totals at the bottom of each column but would like them to appear automatically on the final report). Can anyone help?
    Here is the query so far:
    SELECT T0.State1 AS 'Bill-to State',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 1 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JAN Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 2 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'FEB Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 3 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAR Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 4 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'APR Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 5 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'MAY Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 6 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUN Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 7 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'JUL Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 8 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'AUG Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 9 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'SEP Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 10 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'OCT Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 11 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'NOV Amt',
    (SELECT SUM(T1.DocTotal) FROM OINV T1 with (NOLOCK)
    INNER JOIN OCRD T2 ON T2.CardCode=T1.CardCode
    WHERE MONTH(T1.DOCDATE) = 12 AND T2.State1 = T0.State1
    AND YEAR(T1.DOCDATE) = YEAR(GETDATE())) AS 'DEC Amt'
    FROM dbo.OCRD T0
    LEFT JOIN dbo.OINV T1 ON T1.CardCode = T0.CardCode
    GROUP BY T0.State1
    ORDER BY T0.State1
    Thanks in advance
    Cathal

    Hi,
    Try this query:
    Select [S] as State, [W] as warshouse,[Jan]= sum([1]), [Feb]= sum([2]), [Mar]= sum([3]), [Apr]= sum([4]),  [May]= sum([5]), [June]= sum([6]), [July]= sum([7]), [Aug]= sum([8]), [Sept]= sum([9]), [Oct]= sum([10]), [Nov]= sum([11]), [Dec]= sum([12]), total = sum (isnull([1],0)+ isnull([2],0) + isnull([3],0) + isnull([4],0) +  isnull([5],0) + isnull([6],0) + isnull([7],0) + isnull([8],0) + isnull([9],0)+ isnull([10],0) + isnull([11],0) + isnull([12],0))
    from(
    SELECT T0.[State1] as S, T2.[WhsCode] as W,month(T1.[DocDate]) as month, sum(T1.[DocTotal]) as T FROM OCRD T0  INNER JOIN OINV T1 ON T0.CardCode = T1.CardCode INNER JOIN INV1 T2 ON T1.DocEntry = T2.DocEntry WHERE year(T1.[DocDate]) = year(getdate()) GROUP BY T0.[State1], T2.[WhsCode],T1.[DocDate] ) s
    Pivot
    (sum(t) for month IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    group by [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[S],[W]
    Thanks & Regards,
    Nagarajan

  • A report to show 2008 Customer Sales by State.

    My customer needs a report to show 2008 Customer Sales by State.  I don't see any SAP reports that will do this.  Is the state held in any of the document files that I could use to create a query??  Or does anyone have a query that reports this information?

    Try using following query:
    SELECT T0.CardCode, T0.CardName, T0.DocNum, T0.DocDate, T0.DocTotal, T1.State
    FROM OINV T0
    INNER JOIN CRD1 T1 ON T0.CardCode = T1.CardCode
    AND T0.ShipToCode = T1.Address
    Though A/R Invoice, does not store the state code separately, it does store the addresscode, which was used for shipping, which could be linked to the Addresses table. Though if the user changes the address manually, than there is no other way, but to do some programming and find the address name, though it will be pretty difficult, because users might not always be correct with their spellings.
    Rahul

  • Help needed on income statement query....

    Hello BW gurus,
    I need to make an income-statement query which gives the following output.
    The 5 Variables are                    
         Company Code          
         Plant               
         Fiscal Period     (12 months) in column     
         Value Type               
         Version               
    #ACCOUNT          0METYPE     METYPE-DESCRIPTION     COMPANYCODE PLANT SALES0RG
         Sales               
         Cost of Sales               
         Gross Margin               
         (Sales minus Cost Of Sales)               
         General &Admin               
         Other               
         Operating Income               
         (Gross margin minus G&A minus Other)               
         Interest Income               
         Interest Expense               
         Net Income before Tax               
         (Operating Income minus Interest Income - Interest expense)               
         Taxes               
         Net income               
         (Net Income before Tax minus Taxes)               
    Note: Sales,cost of sales,general and admin,other,interesat income,interest expense,taxes are under the hierarchy of ACCOUNT.
    Please make a quick response.
    100% points will be awarded.
    Thanks in advance.
    Sam Mathew

    Please read these:
    When your query takes too long
    When your query takes too long ...
    How to Post a SQL statement tuning request
    HOW TO: Post a SQL statement tuning request - template posting

  • How to edit the records value fetched by select statement query in sqldever

    How to edit the records value fetched by select statement query in sqldever 2.1.1.
    EX-
    SELECT * FROM emp WHERE ename like 'Jaga%'
    Edited by: user9372056 on Aug 31, 2010 2:16 AM

    Hi,
    Although some forum members may be using that tool, there is still a dedicated forum for SQL Developer.
    SQL Developer
    Maybe your chances are better there.
    Regards
    Peter

  • Cash flow statement Query

    Hi,
    I had used the RSZC transaction to migrate query 0FIGL_VC1_Q0002 - Cash flow statement, based on 0FIGL_VC1 to a custom virtual cube which extracts data from a cube containing general ledger accounting (New) data. on execution of the query, no data is displayed.
    In a similar fashion the query 0FIGL_V10_Q0001, which is based on virtual cube 0FIGL_V10 was migrated to the same custom virtual cube and was found to be executing.
    has anyone faced similar issue with cash flow statement query?
    Regards,
    Sainath

    Look at the import parameters  - there is a hard coded and change it to Z version
    https://forums.sdn.sap.com/click.jspa?searchID=10104420&messageID=5012838
    Hope it Helps
    Chetan
    @CP..

  • Printing Prepared Statement Query

    Hi all,
    Is it possible to print Prepared Statement query. When i give System.out.println(query);, i get the query with '?' and not with the actual value sent. How can i print the query with the value passed in place of the '?' ?

    Hi all,
    Is it possible to print Prepared Statement
    tatement query. When i give
    System.out.println(query);, i get the query with '?'
    and not with the actual value sent. How can i print
    the query with the value passed in place of the '?' ?The simple answer is that you can't (AFAIK), but some database drivers are able to log the sql statements.
    Kaj

  • Stock Statement Query

    Hi All,
    Can some one help me in writing the stock statement query which includes
    Warehouse Code, Inventory Transfer No, Inventory Transfer Date, Item Code, Item Description, Batch No/Serial No, Expiry date, Delivery Note No if any
    We have add on which links the Inventory Transfer to Delivery. We can copy the inventory transfers to delivery where inventory transfer no will be stored in the item level UDF (u_delno)
    Thanks in advance

    Try from here to start:
    Select T1.WhsCode, T0.DocNum, T0.DocDate, T1.ItemCode, T1.Dscription, T1.SerialNum, T1.u_delno
    FROM dbo.OWTR T0
    INNER JOIN dbo.WTR1 T1 ON T1.DocEntry = T0.DocEntry
    Thanks,
    Gordon

  • EJB Transaction timeout and Statement Query Timeout

    I am looking for some details on how statement query timeout is set when statement execution is part of the session bean transaction. I have done some test in webshere 6.1. and JBoss 5.0 and not getting the desired behavior. My understanding is following
    - DB is Oracle 11g
    - EJB transaction is set to 5 mins.
    - Query time out setting is set to default vaule (not sure what is the default value)
    - Session bean is updating say customer record using PreparedStatement
    - Prior to calling session bean method I am locking the customer record using external/db tool and holding the lock.
    - Call session bean method. Method waits endlessly for the lock to be acquired. No transaction rollback after 5 mins.
    - After 10 minutes commit the transaction in the external db tool
    - Session bean methods throws transaction rollback.
    My understanding was that query timeout is set based on transaction "time to live". Please share out thoughts.
    Edited by: hdjava on Jun 18, 2010 1:06 PM
    Edited by: hdjava on Jun 18, 2010 1:07 PM

    The following configuration seems working:
    version: OC4J (9.0.3.0.0) (build 020927.1699)
    AM deployment:
    - bc4j.xcfg: <jbo.ejb.txntimeout>30000</jbo.ejb.txntimeout>
    - orion-ejb-jar.xml: <session-deployment name="..." timeout="0"/>
    OC4J config:
    - data-source: inactivity-timeout="30000"
    This keeps connection open for more than default 30 mins of inactivity (30000 secs configured).
    Although, oc4j console prints multiple warnings:
    DriverManagerConnectionPoolConnection not closed, check your code!
    Looks like this is not an intended usage - but working.
    Notice that it was a test, not a production environment.
    Also pls see 9033: AM as EJB Session bean: pooled connection lost for new txn
    I would be thankful for any experience in running AM Session EJB w/o timeout.

  • General stock statement query.

    hi ,
         can anybody help me in getting stock statement query.... no selection criteria it has to disply all the ware house with Opening stock......inward qty, outward qty,closing stock . (this general) and like this i have to get stock details date wise

    Hi Vignesh......
    I'm in confusion. You are asking the same question with different meanings.
    As you are already suggested to use Inventory Posting List. You get all of your answers to your question.
    It will give you the stock Opening, In, Out, Closing Warehouse Wise (Particular/All), Date wise, Transaction wise...
    Please check this path to refer This Report.
    Inventory->Inventory Reports-->Inventory Posting List......
    If you have different requirement then please do mention.
    Regards,
    Rahul

  • Stock statement query--- help

    Have any one got the stock statement query report in the folowing format....
    1.ItemCode
    2.Item Description
    3.Item Price
    4.Opening
    5.Receipts
    6.Issues
    7.Closing
    8. Value
    The selection criteria are:
    3.Posting Date
    from wh
    to wh
    help me in making stock statement query
    regards,
    Vignesh

    Hi
    Check This
    select w0.itemcode, i0.docdate, w0.whscode, w0.onhand - isnull (sum (i0.inqty - i0.outqty), 0), 0
    from oitw w0 left outer join oinm i0 on w0.itemcode = i0.itemcode and w0.whscode = i0.warehouse
    where i0.docduedate >= [%0]
    group by w0.itemcode, w0.whscode, w0.onhand, i0.docdate
    having w0.itemcode = [%1] and w0.onhand - isnull (sum (i0.inqty - i0.outqty), 0) >= 0
    union
    select w0.itemcode, i0.docdate, w0.whscode, 0, -(w0.onhand - isnull (sum (i0.inqty - i0.outqty), 0))
    from oitw w0 left outer join oinm i0 on w0.itemcode = i0.itemcode and w0.whscode = i0.warehouse
    where i0.docduedate >= [%0]
    group by w0.itemcode, w0.whscode, w0.onhand, i0.docdate
    having w0.itemcode = [%1] and w0.onhand - isnull (sum (i0.inqty - i0.outqty), 0) < 0
    or
    SELECT T0.ITEMCODE, T0.DSCRIPTION,T0.OPENQTY, T0.OPENVALUE, T0.INQTY, T0.INQTY*T0.PRICE AS 'RCPT VAL', T0.OUTQTY,T0.OUTQTY*T0.PRICE AS 'ISS. VAL', T0.INQTY-T0.OUTQTY AS 'CLOSING STOCK QTY',((T0.INQTY-T0.OUTQTY)*(T0.CALCPRICE)) AS 'CLOSING STOCK VAL' FROM OINM T0 WHERE T0.DOCDATE >=[%0] AND T0.DOCDATE <=[%1]
    Thanks
    Kevin
    Edited by: Kevin Shah on Oct 23, 2010 5:37 PM

  • Sales order invoice query

    Hi
    Please send the sales order invoice query as basic columns.. Further I will modify the query according to the requirement.
    Pleas send to my personal ID: [email protected]
    Thanks
    Sree

    Thanks.  There's a few problems though.
    1)  It seems that OINV DocTotal != Balance Due.  I'm seeing a number of invoices where there was a balance due, but we applied additional money (either we took another incoming payment and applied it or applied money from the account balance, etc.) and yet it still shows a total.
    2)  It's pulling incoming payments from different customers.  I think this is because the table was joined based on "RCT2 T4 on T4.[DocEntry]  =  T3.[DocNum] and T4.[InvoiceId] = T2.[LineNum]"  In one example I have 2 incoming payments 446 and 614.  Both have the DocEntry 542, but one relates to A/R Invoice 542 (for a different client) while the other relates to Down Payment Invoice 542.  *I was able to fix this by adding WHERE T5.CardCode = [%0]*
    3)  I'm going to work with this a little bit and see if I can alter it to make it work for me.  Basically this query falls a little short on the following:
    -  Doesn't include incoming payments that aren't linked to a down payment invoice.
    -  Does not give the Invoice Total (I'd like to know how much of the SO was invoiced.  DocTotal seems to give me Amount Invoiced - Down Payments.  I'm not sure the best way to get this number.  Maybe I could do the sum of each line * tax + freight)
    -  Does not give the outstanding amount on an invoice.  The ARtotal [DocTotal] column gives me how much was owed when the invoice was created, but it doesn't tell me what is currently owed.
    -  Lastly it may complicate the query too much and could be left off, but it would be nice to see if they have any money from credits or incoming payments that has not been applied.  Perhaps this would be easily accomplished by simply pulling in their account balance.

  • Sales Order + Activity query

    Hi,
    I set up the following query in one company:
    SELECT T0.DocNum, T1.ClgCode, T3.U_NAME, T2.name, T1.endDate, T1.Priority, T0.CardCode, T0.CardName, T0.NumAtCard, T0.DocDate, T0.DocTotal
    FROM ORDR T0 LEFT OUTER JOIN OCLG T1 ON T0.DocNum = T1.DocNum LEFT OUTER JOIN OCLA T2 ON T1.status = T2.statusID LEFT OUTER JOIN OUSR T3 ON T1.AttendUser = T3.INTERNAL_K
    WHERE T0.DocStatus = 'O'
    When I replicate it in another company, I get the following error:
    SQL Server Native Client 10.0|| SQL Server||  Conversion failed when converting the nvarchar value 'STBs-EN-0002' to data type int. 'Received Alerts' (OAIB)
    The STBs value indicated is an Item Code/IMD record which isn't even referred to in the query so not sure why it's getting picked up and/or causing an error.
    When I separate the two parts of the query - one query on just open sales orders, another on activities - they both work. It seems to be with the linking of ORDR to the Activities tables (if I try just ORDR and OCLG I get the same error above).
    Any assistance on figuring out how to fix the query would be much appreciated,
    Heather

    Hi Heather,
    Try:
    SELECT T0.DocNum, T1.ClgCode, T3.U_NAME, T2.name, T1.endDate, T1.Priority,
    T0.CardCode, T0.CardName, T0.NumAtCard, T0.DocDate, T0.DocTotal
    FROM ORDR T0
    LEFT JOIN OCLG T1 ON T0.DocNum = T1.DocNum AND T1.DocType = '17'
    LEFT JOIN OCLA T2 ON T1.status = T2.statusID
    LEFT JOIN OUSR T3 ON T1.AttendUser = T3.INTERNAL_K
    WHERE T0.DocStatus = 'O'
    Thanks,
    Gordon

  • Reversal of Input VAT credit taken in case of EOU sales within State

    Dear All,
    Whenever my client sells material to EOU within state, they have to reverse the corresponding input tax credit taken on the Raw material purchase from the supplier from the same state. if they supply the same from imported materials or from interstate purchase, this provision is not applicable.
    I have few doubts..
    1. How can I establish a link between Raw Materials for input tax credit and FGs to be sold to EOU. I have no separate material codes for FGs on basis on different kind of sales.
    2. How the accounting entries should pass in SAP system and what tax conditions or change in SD pricing procedure should I maintain?
    Thanking all in advance.

    Though couple of suggestions are there to delete manually, for me, it is not adviceable.  This is due to the fact that when the original billing was generated, the corresponding VAT would have been debited to customer account.
    Now when the return order is created and let us assume you delete manually those VAT condition types and subsequently generate a credit note on customer.
    In this circumstances, from FI point of view, this is wrong because, for the debit entry, you have to pass a credit entry also; only then the loop will close.  When original billing was generated, the corresponding tax value would have been debited to customer account and if you do not adjust this entry, then this amount will show as a debit entry in customer account.
    So from FI side, suitable exit should be applied in such a way not to take credit of such returns.
    thanks
    G. Lakshmipathi

  • Sales By Amt Query Change

    Hello All -
    We have this Query used to view sales by Amt for each month.  Can we modify it so it does not show every month.  Instead, gives option to select the month at the start of the Query and only shows the month selected in the results?
    Keep everything else the same.
    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) AS 'JAN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 2 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'FEB Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 3 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'MAR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 4 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'APR Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 5 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'MAY Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 6 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'JUN Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 7 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'JUL Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 8 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'AUG Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 9 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'SEP Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 10 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'OCT Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 11 AND T1.ITEMCODE
    = T0.ITEMCODE) AS 'NOV Amt',
    (SELECT SUM(T1.QUANTITY*T1.PRICE) FROM INV1 T1 with
    (NOLOCK) WHERE MONTH(T1.DOCDATE) = 12 AND T1.ITEMCODE
    = T0.ITEMCODE) 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

    This would not be possible through a simple SQL.  You will need a combination of a VIEW or Stored Procedure.
    The Base query for getting the Start and Ending Month
    DECLARE @FROM VARCHAR(10), @TO VARCHAR(10)
    /* SELECT FROM  [dbo].[OFPR] T0 WHERE */ SET @FROM = /* T0.Code */ '[%0]'
    /* SELECT FROM  [dbo].[OFPR] T0 WHERE */ SET @TO = /* T0.Code */ '[%1]'
    SELECT (SELECT T0.F_RefDate FROM  [dbo].[OFPR] T0 WHERE T0.Code = @FROM) [FROM MONTH], (SELECT T0.T_RefDate FROM  [dbo].[OFPR] T0 WHERE T0.Code = @TO) [TO MONTH]

Maybe you are looking for

  • Can't find driver for printer

    I have an HP PSC 750 connected to an airport express base station. It shows up in the printer browser when I click the add printer button (it says Bonjour under the connection type). However, under the 'print using' drop menu it won't auto select a d

  • Dynamic Menu not displaying correctly on iOS devices

    Can't get my dropdown menus to display correctly when viewing on iPhone & iPad. For some reason the submenu will become visable but not let me select anything before disappearing again. Works fine on desktop browsers.

  • Aperture 3 and HDV Camcorder

    I've been messing around with Aperture 3 for a while now and decided it was time to try playing with the new HD video support. On Apple's Aperture "New Features" page http://www.apple.com/aperture/features/#video it states: "Video Support Import, bro

  • CHARACTER MODE REPORTS PROBLEM

    Hi All, My application has both GUI & CUI reports. Printers have also been installed in the Sun SPARC server on which the application is running. I have set my output to be generated to a file at design time in the system parameters. While executing

  • [SOLVED] No sound in skype nor grooveshark but in phonon

    I am stuck with this problem. I've tried it all without success.. (arch forums, google, ...) I have snd-had-intel installed and in phonon (KDE) i can hear the sound. However, if I open grooveshark or skype, there is no sound. The most strange is that