Sales Analyses / sql Query

Hello All,
is there a possibillity to catch/copy the sales analyses reports as User Query?
we need a existng Sales analyses Report but with some other informations which are not included in the standard report.
so my thinking was may we can copy the sales analyses report and create a User query with the missed information?
Thanks and best regards
Serkan

Hallo Christian, Hallo Serkan,
das ist nur die halbe Wahrheit. Die Queries von B1 sind nach meiner Recherche in der Common DB abgelegt. Ob und in wie weit es sinnvoll ist, die Einträge per SQl Studio zu ändern lasse ich mal dahingestellt.
Theoretisch ist es also möglich, wenn du mit dem SQL Profiler schaust, welches Query ausgeführt wird, diesen Eintrag in den Tabellen zu suchen und entsprechend abzuändern.
Aber wie schon oft gesagt, man sollte die Finger von der Tabellen Struktur und den Einträgen der B1 DB lassen.
Grüße Steffen
P.S. Ich hab mich auch schon darüber geärgert, dass man die SAP internen Berichte nicht anpassen kann.

Similar Messages

  • Sales Analysis customization query

    Hi Experts
    I'm currently using this query to give me customized sales analysis.   Essentially we just want to include the Sales Employee name on the report.
    In most cases it matches the SAP B1 Sales Analysis report but there are also some differences.    Can anyone point me in the direction of what I should be looking for in order make it match the Sales Analysis more closely?
    SELECT P.[CardCode],P.[CardName],P.[SlpName],
    ISNULL([1],0) as [Jan],
    ISNULL([2],0) as [Feb],
    ISNULL([3],0) as [Mar],
    ISNULL([4],0) as [Apr],
    ISNULL([5],0) as [May],
    ISNULL([6],0) as [Jun],
    ISNULL([7],0) as [Jul],
    ISNULL([8],0) as [Aug],
    ISNULL([9],0) as [Sep],
    ISNULL([10],0) as [Oct],
    ISNULL([11],0) as [Nov],
    ISNULL([12],0) as [Dec]
    FROM (SELECT T0.CARDCODE, T0.CARDNAME, T2.SlpName,(T1.Doctotal-T1.VatSum-T1.TotalExpns) AS [BAL],MONTH(T1.Docdate) as [month] FROM dbo.OCRD T0
    LEFT JOIN dbo.oslp t2 on t0.slpcode=t2.slpcode         
    LEFT JOIN dbo.OINV T1 ON T1.CardCode = T0.CardCode AND Year(T1.Docdate) = 2014
              UNION
              SELECT T0.CARDCODE, T0.CARDNAME,T2.SlpName,(T1.Doctotal-T1.VatSum-T1.TotalExpns)  AS [BAL],MONTH(T1.Docdate) as [month] FROM dbo.OCRD T0  
    LEFT JOIN dbo.oslp t2 on t0.slpcode=t2.slpcode  
    LEFT JOIN dbo.ORIN T1 ON T1.CardCode = T0.CardCode AND Year(T1.Docdate) = 2014 ) S
              PIVOT  (SUM(S.[BAL]) FOR [month] IN
             ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    Order By P.CardCode

    Hi,
    Try this:
    SELECT P.[CardCode],P.[CardName],P.[SlpName],
    ISNULL([1],0) as [Jan],
    ISNULL([2],0) as [Feb],
    ISNULL([3],0) as [Mar],
    ISNULL([4],0) as [Apr],
    ISNULL([5],0) as [May],
    ISNULL([6],0) as [Jun],
    ISNULL([7],0) as [Jul],
    ISNULL([8],0) as [Aug],
    ISNULL([9],0) as [Sep],
    ISNULL([10],0) as [Oct],
    ISNULL([11],0) as [Nov],
    ISNULL([12],0) as [Dec]
    FROM (SELECT T0.CARDCODE, T0.CARDNAME, T2.SlpName,(T1.Doctotal-T1.VatSum-T1.TotalExpns) AS [BAL],MONTH(T1.Docdate) as [month] FROM dbo.OCRD T0
    LEFT JOIN dbo.oslp t2 on t0.slpcode=t2.slpcode         
    LEFT JOIN dbo.OINV T1 ON T1.CardCode = T0.CardCode AND Year(T1.Docdate) = 2006
              UNION
              SELECT T0.CARDCODE, T0.CARDNAME,T2.SlpName, - (T1.Doctotal-T1.VatSum-T1.TotalExpns)  AS [BAL],MONTH(T1.Docdate) as [month] FROM dbo.OCRD T0  
    LEFT JOIN dbo.oslp t2 on t0.slpcode=t2.slpcode  
    LEFT JOIN dbo.ORIN T1 ON T1.CardCode = T0.CardCode AND Year(T1.Docdate) = 2006 ) S
              PIVOT  (SUM(S.[BAL]) FOR [month] IN
             ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    Order By P.CardCode
    Thanks & Regards,
    Nagarajan

  • Sales Analysis detailed display

    Hi,
    Right now it have to double click on row number to display the detailed of the records.
    Is it possible to display on the same page without double click?
    Thanks

    Hi,
    Please check following threads. Let me know whether meet your requirements:
    Sales analysis report - in query form?
    Sales Analysis query
    Sales Analysis Report by Customer( Monthly)
    Sales Analysis customization query
    Thanks & Regards,
    Nagarajan

  • Query to match Sales Analysis output exactly

    Hello,
    I have tried several queries to match the output of the Sales Analysis report.  I have done so by customer and by sales employee.  I have failed to create a query that always matches the outcome of the Sales Analysis query exactly.  I would greatly appreciate it if someone could provide such a query even if it just matches net A/R invoice total by date range so that it can be compared with Sales Analysis tool.  From there I can use joins to see other results, e.g., net sales by sales employee by customer.
    Thank you,
    Lang

    Thanks for your response.  Yes, we need to account for credit memos and have already done so.  I had not thought to check for canceled state on invoices though, so thanks for that.  I did a quick query and there were no canceled invoices in the database, however, it will be good to incorporate regardless.  My annual net is close to being correct, but must be exact.  I don't need any other information to be output except net balance, i.e., balance after credit memos, document discounts, miscellaneous expenses recorded in freight field, and ?.  Using doctotal on documents takes into account the document discounts and miscellaneous expenses.  Another way to go is work at the line item level, e.g., INV1 or JDT1, and then account for the document discount and freight (totalexpns).  Approaches that use INV1 linetotal naturally fail on their own since they don't account for document discounts and freight expenses.  At the risk of being redundant, any approaches that don't include credit memos will naturally fail as well.  Here is a few approaches I have tried (that have been almost correct, but not exact, i.e., off by hundreds or a few thousand with net being in the single digit millions):
    Approach #1:
    declare @start datetime
    declare @end datetime
    set @start = '01/01/2008'
    set @end = '12/31/2008'
    select sum(t2.subtotal) from (select t0.doctotal as subtotal
    from oinv t0
    where t0.docdate between @start and @end
    union all
    select -1*t0.doctotal as subtotal
    from orin t0
    where t0.docdate between @start and @end) t2
    Note: this approach was off by a couple hundred dollars or so.  I would like to run this query in B1, but it summarizes a union and that seems to cause B1 to not be able to handle it. It runs fine in any other SQL Server client.  I would rather run it in B1 with dynamically selectable start and end dates, via '[%0]' etc.  The same is true for Approach #2 below.
    Approach #2:
    declare @start datetime
    declare @end datetime
    set @start = u201801/02/2008u2019
    set @end = u201812/31/2008u2019
    Select sum(t5.subtotal) from (Select SUM as subtotal
    From INV1 T0
    Inner JOIN OINV T1 ON T1.DocEntry = T0.DocEntry
    Where T1.DocDate BETWEEN @start AND @end
    Union All
    Select -SUM as subtotal
    From RIN1 T0
    Inner JOIN ORIN T1 ON T1.DocEntry = T0.DocEntry
    Where T1.DocDate BETWEEN @start AND @end
    union all
    select sum(t0.totalexpns) as subtotal
    from oinv t0
    where t0.docdate between @start and @end union all
    select sum(t0.totalexpns) as subtotal
    from orin t0
    where t0.docdate between @start and @end) t5
    Note: the outcome of this is identical to Approach #1. 
    Approach #3:
    SELECT SUM as u2018Net Balanceu2019
    from JDT1 T0
    Inner Join OJDT T1 ON T1.TransId = T0.TransID and
    (T1.TransType = u201813u2019 or T1.TransType = u201814u2019)
    Inner Join OCRD T2 ON T2.CardCode = T0.ShortName
    LEFT JOIN OINV T3 ON T3.TransId = T1.TransId
    LEFT JOIN ORIN T4 ON T4.TransID = T1.TransId
    Where T1.refdate Between u2018[%0]u2019 and u2018[%1]u2019 and T2.CardType = u2018Cu2019
    Note: This query fails because it does not account for miscellaneous expenses recorded in the freight field of invoices and credit memos.  Adding those in is possible, but fails due to the 'Inner Join OCRD T2 ON T2.CardCode = T0.ShortName.  This is because in the case of freight expense journal line items the shortname does not match the cardcode of the BP, but rather the system account it references.  I haven't spent more time to rework the logic of the join to overcome this, but it could possibly be added back in via a union which is subsequently totaled.
    I think I tried a few other approaches as well, but to no avail. 
    A related question/annoyance: I have noticed that certain queries in B1 cannot be executed correctly (they throw an error or have strange behavior like returning only the first row returned) though they can run fine in SQL Server Manager or other SQL Server clients.  Why is that?  It is annoying and unrealistic to have clients have to use another tool for certain queries.  Examples of such queries are those involving cursors, certain summarizing selects that work on a union as input, and queries that contain certain elements of TSQL, like variable declarations (not sure about this last one, but it seems to sometimes cause the query to fail in B1).  I wish I knew how to overcome this so that all queries could run in B1.
    Edited by: Lang Riley on Jan 22, 2009 8:08 PM
    Edited by: Lang Riley on Jan 22, 2009 8:15 PM

  • Sales Analysis Query

    Dear Experts,
    Want to Sales Analysis Query same as Sales Analysis in SAP
    In standard SAP when we run report with anual slection criteria for eg, 01/04/2010 To 31/03/12
    it's show in one column not display in compare with Quaterwise & Monthwise report.
    Result for query is
    Customer Code, Customer Name, Year2010 (Sales), Year2011 (Sales), Year2012 (Sales)
    Please help me.
    BR
    Deep

    Ok........
    It was my query mistake.......
    Please try this......
    SELECT Distinct T0.CardCode,T0.CardName, 
    (isnull((SELECT SUM((case when SUBSTRING((CONVERT(VARCHAR(11),T4.DOCDATE,106)),8,11) like '2006%' then T4.LineTotal else 0 end))
          FROM INV1 T4 WHERE T4.ItemCode=T1.ItemCode ),0)) '2006',
    (isnull((SELECT SUM((case when SUBSTRING((CONVERT(VARCHAR(11),T4.DOCDATE,106)),8,11) like '2007%' then T4.LineTotal else 0 end))
          FROM INV1 T4 WHERE T4.ItemCode=T1.ItemCode ),0)) '2007',
    (isnull((SELECT SUM((case when SUBSTRING((CONVERT(VARCHAR(11),T4.DOCDATE,106)),8,11) like '2008%' then T4.LineTotal else 0 end))
          FROM INV1 T4 WHERE T4.ItemCode=T1.ItemCode ),0)) '2008',
    (isnull((SELECT SUM((case when SUBSTRING((CONVERT(VARCHAR(11),T4.DOCDATE,106)),8,11) like '2009%' then T4.LineTotal else 0 end))
          FROM INV1 T4 WHERE T4.ItemCode=T1.ItemCode ),0)) '2009',
    (isnull((SELECT SUM((case when SUBSTRING((CONVERT(VARCHAR(11),T4.DOCDATE,106)),8,11) like '2010%' then T4.LineTotal else 0 end))
          FROM INV1 T4 WHERE T4.ItemCode=T1.ItemCode ),0)) '2010',
    (isnull((SELECT SUM((case when SUBSTRING((CONVERT(VARCHAR(11),T4.DOCDATE,106)),8,11) like '2011%' then T4.LineTotal else 0 end))
          FROM INV1 T4 WHERE T4.ItemCode=T1.ItemCode ),0)) '2011',
    (isnull((SELECT SUM((case when SUBSTRING((CONVERT(VARCHAR(11),T4.DOCDATE,106)),8,11) like '2012%' then T4.LineTotal else 0 end))
          FROM INV1 T4 WHERE T4.ItemCode=T1.ItemCode ),0)) '2012'
    FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry
    Group By SUBSTRING((CONVERT(VARCHAR(11),T0.DOCDATE,106)),8,11), T1.ItemCode, T0.CardName, t0.CardCode
    Regards,
    Rahul

  • Query vs Sales Analysis Report

    I wrote a query that does virtually the same thing as a sales analysis report -- add up all invoice totals and calculate a gross sales number.
    In the sales analysis report ItemXXX has a total sales of $1456.94
    My query ItemXXX has a total sales of $1457.73
    A $.79 discrepancy which I assumed was a result of the fact that my query doesn't include A/R Credit Memos. Only some items have this discrepancy.
    The problem is that if I do an inventory posting list on the item there are no A/R Credit Memos listed. Only A/R Invoices, A/P Invoices, and A/P Goods Receipts.
    What other documents could be affecting this number? Any other things that could be causing this?
    Thanks,
    -Steve

    Hi Nagarajan,
    Im user of Sap Business One, i need the completly query for obtain the Sales Analysis Report
    i have this but in some items dont match
    SELECT  ItemCode,   
            Sum(TotFac) - SUM(TotNC) as  'FacturadoNeto',   
            Sum(GBrutaFac)-SUM(GbrutaNC) as  'GBruta',   
            Round((Sum(GBrutaFac)-SUM(GbrutaNC))/case when  (Sum(TotFac) - SUM(TotNC))= 0 then 1 else (Sum(TotFac) - SUM(TotNC)) end  *100,2) as '% Margen'   
    FROM (   
    SELECT    
    ItemCode = T1.ItemCode, 
    Marca = (Select T2.FirmName from OMRC T2 JOIN OITM T3 on T2.FirmCode = T3.FirmCode where T3.ItemCode=T1.Itemcode), 
    TotFac = Sum(T1.Linetotal),    
    GBrutaFac = SUM(T1.GrssProfit),   
    TotNc= 0,   
    GbrutaNC = 0   
    FROM OINV T0 (NOLOCK) INNER JOIN INV1 T1 (NOLOCK) ON T0.DocEntry = T1.DocEntry                                    
    WHERE (T0.[DocDate] >='20140101' AND  T0.[DocDate] <='20141231') 
      and T0.DocType  = 'I' -- solo facturas por articulos   
    Group by  T1.ItemCode  
    Union   
    SELECT    
    ItemCode = T1.ItemCode,   
    Marca = (Select T2.FirmName from OMRC T2 JOIN OITM T3 on T2.FirmCode = T3.FirmCode where T3.ItemCode=T1.Itemcode), 
    TotFac = 0,   
    GBrutaFac = 0,   
    TotNc= Sum(T1.LineTotal),    
    GbrutaNC = SUM(T1.GrssProfit)   
    FROM ORIN T0 (NOLOCK) INNER JOIN RIN1 T1 (NOLOCK) ON T0.DocEntry = T1.DocEntry                                    
    WHERE (T0.[DocDate] >='20140101' AND  T0.[DocDate] <='20141231')
      and T0.DocType  = 'I' -- solo NC por articulos   
    Group by T1.ItemCode 
    Union
    SELECT    
    ItemCode = T1.ItemCode,   
    Marca = (Select T2.FirmName from OMRC T2 JOIN OITM T3 on T2.FirmCode = T3.FirmCode where T3.ItemCode=T1.Itemcode), 
    TotFac = 0,   
    GBrutaFac = 0,   
    TotNc= Sum(T1.LineTotal),    
    GbrutaNC = SUM(T1.GrssProfit)   
    FROM ODPI T0 (NOLOCK) INNER JOIN DPI1 T1 (NOLOCK) ON T0.DocEntry = T1.DocEntry                                    
    WHERE (T0.[DocDate] >='20140101' AND  T0.[DocDate] <='20141231')     
      and T0.DocType  = 'I' -- solo Fact Anticipos por articulos   
    Group by T1.ItemCode
    ) T   
    Group by  ItemCode, Marca

  • Query to mimic the items tab of the Sales Analysis report.

    Hi there,
    I'm currently looking to create a query that mimics the behaviour of the Sales Analysis report in B1. The items tab of the Sales Analysis report provides all the data I require - the only issue is that I would like to merge this data with some other data regarding current on hand stock quantities etc. and therefore I would like to be able to pull out the query behind the Sales Analysis report.
    I'm assuming this cannot be done and therefore I'm attempting to build a query to replicate the results. The query needs to show Item No, Item Description, Quantity Sold, Sales Amt (in system currency), Gross Profit and Gross Profit % for items within a given period.
    If this can be done relatively easily, can the query then be modified to show all items (including items that haven't sold in the date range) merely with '0' for Quantity Sold, Sales Amt etc. if the item hasn't been sold in the period, and the appropriate figures if each of these columns if the item has sold. I assume some kind of CASE statement can be used to generate this.
    So the query needs to show Item No, Item Description, Current quantity in stock, Quantity Sold, Sales Amt (in system currency), Gross Profit and Gross Profit % for all items within a given date range.
    I hope you can assist me with this problem.
    Thanks
    Grant.

    Hi,
    Thanks Gordon that was exactly what I needed.
    I've been trying to add some additional columns to the query but I'm experiencing some errors and I can't quite tell why.
    Basically, here's the code from another working query I have which I wish to merge into the query you've suggested above:
    SELECT T0.[ItemCode],
    T0.[ItemName],
    T3.[ItmsGrpNam],
    T4.[Name] AS [Sub-Category],
    T5.[Name] AS [Sub-Sub-Category],
    T0.[CardCode] AS [Pref Supplier],
    T6.[FirmName] AS [Brand],
    T0.[U_Range],
    T0.[OnHand],
    CASE WHEN T0.[StockValue] = 0 THEN 0 ELSE T0.[StockValue] END AS [StockValue],
    T1.[Price] AS [PBK GBP Price],
    CASE WHEN T0.[OnHand] = 0 THEN T0.[LastPurPrc] ELSE T0.[StockValue]/T0.[OnHand] END AS [Ave Cost],
    CASE WHEN T0.[OnHand] = 0 THEN T1.[Price]-T0.[LastPurPrc] ELSE CASE WHEN T0.[OnHand] > 0 THEN T1.[Price]-T0.[StockValue]/T0.[OnHand] END END AS [Margin],
    CASE WHEN T0.[OnHand] = 0 AND T0.[LastPurPrc] = 0 THEN 0 ELSE CASE WHEN T0.[OnHand] > 0 AND (T0.[StockValue]/T0.[OnHand]) = 0 THEN 0 ELSE CASE WHEN T0.[OnHand] = 0 THEN (T1.[Price]-T0.[LastPurPrc])/T1.[Price]*100 ELSE CASE WHEN T0.[OnHand] > 0 THEN (T1.[Price]-T0.[StockValue]/T0.[OnHand])/T1.[Price]*100 END END END END AS [Margin %],
    T0.[LastPurPrc]
    FROM [dbo].[OITM]  T0 INNER JOIN [dbo].[ITM1]  T1 ON T0.ItemCode = T1.ItemCode INNER JOIN [dbo].[OITB]  T3 ON T0.ItmsGrpCod = T3.ItmsGrpCod LEFT OUTER JOIN [dbo].[@U_SUBCATEGORY]  T4 ON T0.U_Subcategory = T4.Code LEFT OUTER JOIN [dbo].[@U_SUBSUBCATEGORY]  T5 ON T0.U_SubSubCategory = T5.Code INNER JOIN OMRC T6 ON T0.FirmCode = T6.FirmCode
    WHERE T0.[OnHand] >= 0 and T0.U_Range not in ('E','X')  
    ORDER BY T0.[ItemCode]
    Essentially I just wish to add the fields which are specified in the query above, but not in the query you've already suggested:
    SELECT T0.ItemCode,
    Max(T0.ItemName),
    Max(IsNull(T0.OnHand,0)) 'In Stock',
    SUM(IsNull(T1.Quantity,0)) 'Quantity',
    Sum(IsNull(T1.LineTotal,0)) 'Sales Amt',
    SUM(IsNull(T1.GrssProfit,0)) 'Gross Profit',
    Case WHEN Sum(Isnull(T1.LineTotal,0)) = 0 THEN 0 ELSE
    SUM(IsNUll(T1.GrssProfit,0))/Sum(Isnull(T1.LineTotal,0)) * 100 END 'Gross Profit %'
    FROM dbo.OITM T0
    LEFT JOIN dbo.INV1 T1 ON T1.ItemCode=T0.ItemCode
    LEFT JOIN dbo.OINV T2 ON T2.DocEntry=T1.DocEntry AND T2.DocDate Between [%0] AND [%1]
    GROUP BY T0.ItemCode
    I was hoping it would be fairly straight forward but so far I've had limited success.
    What am I missing here?
    Thanks in advance!

  • Sales Analysis report results are being affected (or eliminated) by SQL

    When running Sales Analysis by Item (Item Tab), the client keys in item 15454*
    in the From and To Field and selects the first and last Item Codes listed
    in the result set. The first item code is The results of the Sales Analysis report includes items from 15454-048E-1-41.3 through 15454E-XC-10G.
    The result set stops at itemcode 15454-EIA-SMB-B84 despite that fact that there
    are many items with sales with Item Codes higher than the 15454-EIA-SMB-B84.
    The SAP support rep highlighted that the application is ignoring the dash in it's filtering priority even thought the item lookup is accounting for the dash.  The response is that this is the behavior of SQL server.
    It is true that SQL does ignore dashes and possibly other special characters in sorting nvarchar fields.  However, it is important that the lookup (to select a range of items) and the result set remain consistant in the application regardless of the database/datatype. 
    With no ability to customize (or fix) the report from the field, we are requesting this a a design change.  We recommend testing with all other special characters as to ensure that the report is actually producing accurate results.

    Hi Peter.......
    Welcome to SAP Forum....
    You can try this report which gives you result of Sales Order regardless of Current Status...
    Select * From ORDR T0 Inner Join RDR1 T1 on T0.DocEntry=T1.DocEntry
    Put the desired field in place of * which ever you want in report......
    Regards,
    Rahul

  • Sales analysis report - in query form?

    Good afternoon. Looking for a bit if help/advice.
    I'm not a complete novice to SAP but what I need is confusing me slightly. I understand the sales analysis report uses many different table as part of its calculations. A company I've recently began working for, who has had SAP for a while, has used sales analysis reports alongside some bespoke reports that are reporting different data.
    Here is their report:
    SELECT T0.[DocNum] AS 'Invoice No.',  CONVERT(VARCHAR(10),T0.[DocDate], 103) AS 'Invoice Date', T0.[NumAtCard] AS 'Cust Order No.', T4.[ItemCode], T5.[U_MSKU] AS 'Manuf SKU', T4.[Dscription] AS 'Description', T6.[ItmsGrpNam] AS 'Item Group', T4.[Quantity], T4.[Price] AS 'Net Unit Price', T4.[LineTotal] AS 'Net/Line Total', T0.[U_ClientNam] AS 'Client Name', T2.[Name] AS 'Division', T1.[Name] AS 'Business Unit', T3.[StreetS] AS 'Ship-to Street', T3.[CityS] AS 'Ship-to City', T3.[ZipCodeS] AS 'Ship-to Postcode'
    FROM OINV T0
    LEFT JOIN [dbo].[@BUSINESSUNITS]  T1 ON T0.U_Bizunits = T1.Code
    LEFT JOIN [dbo].[@DIVISIONS]  T2 ON T0.U_Division = T2.Code
    INNER JOIN INV12 T3 ON T0.DocEntry = T3.DocEntry
    INNER JOIN INV1 T4 ON T0.DocEntry = T4.DocEntry
    INNER JOIN OITM T5 ON T4.ItemCode = T5.ItemCode
    INNER JOIN OITB T6 ON T5.ItmsGrpCod = T6.ItmsGrpCod
    WHERE T0.[DocDate] BETWEEN [%0] AND [%1]  AND T0.[CardCode] = [%2]
    It just doesn't give the same totals as the sales analysis report but I can't reproduce the sales analysis report. How would I go about getting the right figures? Because what we ideally need is to filter the sales analysis results by some of our custom fields:
    [U_ClientNam], [Name] etc.
    How would I go about this? Can I extract parts of the sales analysis report somehow and run it as a query I can manipulate?
    Thanks.

    Hi, not sure if you meant to link to a thread? Based on the query you have given on this thread no totals appear to match however it is much closer than the simple query.
    SELECT Div, BusUnit, isnull([1],0) as Jan, isnull([2],0) as Feb, [3] as Mar, isnull([4],0) as Apr, isnull([5],0) as May, isnull([6],0) as june, isnull([7],0) as July, isnull([8],0) as Aug, isnull([9],0) as Sept, isnull([10],0) as Oct, isnull([11],0) as Nov, isnull([12],0) as Dec
    from
    (SELECT T1.[LineTotal] as Total, month(T0.[DocDate])as month, T8.[Name] AS BusUnit, T9.[Name] AS Div FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN [dbo].[@BUSINESSUNITS]  T8 ON T0.U_Bizunits = T8.Code INNER JOIN [dbo].[@DIVISIONS]  T9 ON T0.U_Division = T9.Code
    WHERE year(T0.[DocDate]) = 2013 and T0.[CardCode] = 'NOR0001'
    union all
    (SELECT -T1.[LineTotal] as Total, month(T0.[DocDate])as month, T8.[Name] AS BusUnit, T9.[Name] AS Div FROM ORIN T0 INNER JOIN RIN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN [dbo].[@BUSINESSUNITS]  T8 ON T0.U_Bizunits = T8.Code INNER JOIN [dbo].[@DIVISIONS]  T9 ON T0.U_Division = T9.Code
    WHERE year(T0.[DocDate]) = 2013 and T0.[CardCode] = 'NOR0001')) S
    Pivot
    (sum(S.Total) For Month IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    Is what I've just used. Still well off the mark though.

  • Sales Analysis query error

    Experts,
    I have a client show need the Sales Analysis report in one excel file without having to open up each customer line to export this.
    I created the following query, but get the error "Arithmetic overflow error converting expression to data type datetime. 'User-Defined Values' "
    SELECT T0.[DocNum], T0.[ObjType], T0.[DocDate], T0.[DocDueDate], T0.[CardCode], T0.[CardName], T0.[DocTotal], T0.[VatSum], (T0.[DocTotal] - T0.[VatSum]) AS 'Total-Tax', T0.[GrosProfit], (T0.[GrosProfit]/(T0.[DocTotal] - T0.[VatSum])*100) AS 'GrossProfit%'
    FROM OINV T0
    UNION
    SELECT T0.[DocNum], T0.[ObjType], T0.[DocDate], T0.[DocDueDate], T0.[CardCode], T0.[CardName], T0.[DocTotal], T0.[VatSum], (T0.[DocTotal] - T0.[VatSum]) AS 'Total-Tax', T0.[GrosProfit], (T0.[GrosProfit]/(T0.[DocTotal] - T0.[VatSum])*100) AS 'GrossProfit%'
    FROM ORIN T0
    WHERE T0.[DocDate] >=[%0] AND  T0.[DocDate] <=[%1]
    ORDER BY T0.[CardCode]
    Any help in solving this error will be welcome!
    Marli

    Hi Marli,
    Try this:
    SELECT T0.[DocNum], T0.[ObjType], T0.[DocDate], T0.[DocDueDate], T0.[CardCode], T0.[CardName], T0.[DocTotal], T0.[VatSum], (T0.[DocTotal] - T0.[VatSum]) AS 'Total-Tax', T0.[GrosProfit], (T0.[GrosProfit]/(T0.[DocTotal] - T0.[VatSum])*100) AS 'GrossProfit%'
    FROM OINV T0
    WHERE  T0.[DocDate] >=[%0] AND  T0.[DocDate] <=[%1] and T0.VatSum !=0
    UNION
    SELECT T0.[DocNum], T0.[ObjType], T0.[DocDate], T0.[DocDueDate], T0.[CardCode], T0.[CardName], T0.[DocTotal], T0.[VatSum], (T0.[DocTotal] - T0.[VatSum]) AS 'Total-Tax', T0.[GrosProfit], (T0.[GrosProfit]/(T0.[DocTotal] - T0.[VatSum])*100) AS 'GrossProfit%'
    FROM ORIN T0
    WHERE T0.[DocDate] >=[%0] AND  T0.[DocDate] <=[%1] and T0.VatSum !=0
    ORDER BY T0.[CardCode]
    Thanks,
    Neetu

  • Sales Analysis query issue

    Experts,
    I have compiled a Sales Analysis Query for a client who need more information than the Sales Analysis in SBO can give them.
    I have found that if I only run the Months of July and August (choose these randomly) I get the correct amounts in the July and August columns.
    When I add these months to the whole query, July and August gets multiplied. The more invoices I add for a specific customer the more it is multiplied.
    I need to know what is wrong with the whole query. Any help would be appreciated.
    Here is the July & August query that is correct:
    SELECT T0.[CardCode], T0.[CardName],
    (SUM(T9.Debit) - sum(T9.Credit)) AS 'July',
    (SUM(T10.Debit) - sum(T10.Credit)) AS 'August'
    FROM  OCRD T0
    LEFT JOIN JDT1 T9 ON T9.ShortName = T0.CardCode AND Month(T9.Duedate) = 7  AND Year(T9.Duedate) = 2010 AND T9.TransType in ('13','14')
    LEFT JOIN JDT1 T10 ON T10.ShortName = T0.CardCode AND Month(T10.Duedate) = 8 AND Year(T10.Duedate) = 2010 AND T10.TransType in ('13','14')
    WHERE T0.CardType = 'C'
    Group By T0.[CardCode], T0.[CardName]
    Here is the Total query that mulitplies the data per month:
    SELECT T0.CardCode, T0.CardName,
    (SUM(T1.Debit) - sum(T1.Credit)) AS 'Total Sales 2009', ((SUM(T1.Debit) - sum(T1.Credit))/12) AS '2009 Monthly Avg', (SUM(T2.Debit) - sum(T2.Credit)) AS 'Total Sales 2010',
    ((SUM(T2.Debit) - sum(T2.Credit))/Month(GetDate())) AS '2010 Monthly Avg',
    (SUM(T3.Debit) - sum(T3.Credit)) AS 'January 2010',
    (SUM(T4.Debit) - sum(T4.Credit)) AS 'February 2010',
    (SUM(T5.Debit) - sum(T5.Credit)) AS 'March 2010',
    (SUM(T6.Debit) - sum(T6.Credit)) AS 'April 2010',
    (SUM(T7.Debit) - sum(T7.Credit)) AS 'May 2010',
    (SUM(T8.Debit) - sum(T8.Credit)) AS 'June 2010',
    (SUM(T9.Debit) - sum(T9.Credit)) AS 'July 2010',
    (SUM(T10.Debit) - sum(T10.Credit)) AS 'August 2010',
    (SUM(T11.Debit) - sum(T11.Credit)) AS 'September 2010',
    (SUM(T12.Debit) - sum(T12.Credit)) AS 'October 2010',
    (SUM(T13.Debit) - sum(T13.Credit)) AS 'November 2010',
    (SUM(T14.Debit) - sum(T14.Credit)) AS 'December 2010'
    FROM  OCRD T0
    LEFT JOIN JDT1 T1 ON T1.ShortName = T0.CardCode AND Year(T1.Duedate) = 2009 AND T1.TransType in ('13','14')
    LEFT JOIN JDT1 T2 ON T2.ShortName = T0.CardCode AND Year(T2.Duedate) = 2010 AND T2.TransType in ('13','14')
    LEFT JOIN JDT1 T3 ON T3.ShortName = T0.CardCode AND Month(T3.Duedate) = 1  AND Year(T3.Duedate) = 2010 AND T3.TransType in ('13','14')
    LEFT JOIN JDT1 T4 ON T4.ShortName = T0.CardCode AND Month(T4.Duedate) = 2 AND Year(T4.Duedate) = 2010 AND T4.TransType in ('13','14')
    LEFT JOIN JDT1 T5 ON T5.ShortName = T0.CardCode AND Month(T5.Duedate) = 3 AND Year(T5.Duedate) = 2010 AND T5.TransType in ('13','14')
    LEFT JOIN JDT1 T6 ON T6.ShortName = T0.CardCode AND Month(T6.Duedate) = 4 AND Year(T6.Duedate) = 2010 AND T6.TransType in ('13','14')
    LEFT JOIN JDT1 T7 ON T7.ShortName = T0.CardCode AND Month(T7.Duedate) = 5 AND Year(T7.Duedate) = 2010 AND T7.TransType in ('13','14')
    LEFT JOIN JDT1 T8 ON T8.ShortName = T0.CardCode AND Month(T8.Duedate) = 6 AND Year(T8.Duedate) = 2010 AND T8.TransType in ('13','14')
    LEFT JOIN JDT1 T9 ON T9.ShortName = T0.CardCode AND Month(T9.Duedate) = 7 AND Year(T9.Duedate) = 2010 AND T9.TransType in ('13','14') 
    LEFT JOIN JDT1 T10 ON T10.ShortName = T0.CardCode AND Month(T10.Duedate) = 8 AND Year(T10.Duedate) = 2010 AND T10.TransType in ('13','14')
    LEFT JOIN JDT1 T11 ON T11.ShortName = T0.CardCode AND Month(T11.Duedate) = 9 AND Year(T11.Duedate) = 2010 AND T11.TransType in ('13','14') 
    LEFT JOIN JDT1 T12 ON T12.ShortName = T0.CardCode AND Month(T12.Duedate) = 10 AND Year(T12.Duedate) = 2010 AND T12.TransType in ('13','14')
    LEFT JOIN JDT1 T13 ON T13.ShortName = T0.CardCode AND Month(T13.Duedate) = 11 AND Year(T13.Duedate) = 2010 AND T13.TransType in ('13','14')
    LEFT JOIN JDT1 T14 ON T14.ShortName = T0.CardCode AND Month(T14.Duedate) = 12 AND Year(T14.Duedate) = 2010 AND T14.TransType in ('13','14')
    WHERE T0.CardType = 'C'
    Group By T0.CardCode, T0.CardName

    Hi,
    Try this
    SELECT T0.CardCode, T0.CardName,
    (SUM(T1.Debit) - sum(T1.Credit)) AS 'Total Sales 2009', ((SUM(T1.Debit) - sum(T1.Credit))/12) AS '2009 Monthly Avg', (SUM(T1.Debit) - sum(T1.Credit)) AS 'Total Sales 2010',
    ((SUM(T1.Debit) - sum(T1.Credit))/Month(GetDate())) AS '2010 Monthly Avg',
    ((sum(Case DATENAME(month,T1.DueDate) when 'January' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'January' then T1.Credit  else 0 end))) Jan,
    (sum(Case DATENAME(month,T1.DueDate) when 'February' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'February' then T1.Credit else 0 end))[Feb],
    (sum(Case DATENAME(month,T1.DueDate) when 'March' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'March' then T1.Credit else 0 end))Mar,
    (sum(Case DATENAME(month,T1.DueDate) when 'April' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'April' then T1.Credit else 0 end))Apr,
    (sum(Case DATENAME(month,T1.DueDate) when 'May' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'May' then T1.Credit else 0 end))May,
    (sum(Case DATENAME(month,T1.DueDate) when 'June' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'June' then T1.Credit else 0 end))Jun,
    (sum(Case DATENAME(month,T1.DueDate) when 'July' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'July' then T1.Credit else 0 end))Jul,
    (sum(Case DATENAME(month,T1.DueDate) when 'August' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'August' then T1.Credit else 0 end))Aug,
    (sum(Case DATENAME(month,T1.DueDate) when 'September' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'September' then T1.Credit else 0 end))Sep,
    (sum(Case DATENAME(month,T1.DueDate) when 'October' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'January' then T1.Credit else 0 end))Oct,
    (sum(Case DATENAME(month,T1.DueDate) when 'November' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'November' then T1.Credit else 0 end))Nov,
    (sum(Case DATENAME(month,T1.DueDate) when 'December' then T1.Debit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'December' then T1.Credit else 0 end)) Dec
    FROM  OCRD T0
    LEFT JOIN JDT1 T1 ON T1.ShortName = T0.CardCode AND Year(T1.Duedate) = 2010   AND T1.TransType in ('13','14')
    WHERE T0.CardType = 'C'
    group by DATENAME(month,T1.DueDate), T0.CardCode, T0.CardName
    Thanks,
    Neetu

  • SQL Query for weekly sales

    Hi,
    This is my First table: REPORT
    with report as (
    select 'vendor_1' as vendor,to_date('1/1/2012','DD/MM/YYYY') supply_date, 'customer_1'as customer,'item_1' as item1, 110 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,120 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item1,130 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/4/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,140 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/10/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item ,200as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/23/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item,0 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/6/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,160 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/7/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,170 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/8/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,180 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/9/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,190 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/20/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,300 as cost from dual)
    THIS IS MY SECOND TABLE: TEMP_WEEK
    WITH temp_week a s(
    SELECT '01/01/2012 to 07/01/2012' AS week from dual union all
    SELECT '08/01/2012 to 14/01/2012' AS week from dual union all
    SELECT '15/01/2012 to 21/01/2012' AS week from dual union all
    SELECT '22/01/2012 to 28/01/2012' AS week from dual union all
    SELECT '29/01/2012 to 31/01/2012' AS week from dual)
    To find weekly sales i have wrote below query:
    SELECT week,vendor,customer,SUM (cost)
    FROM ( SELECT week,vendor,customer,SUM (cost) cost
    FROM (SELECT CASE
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 THEN
    '01/01/2012 to 07/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 THEN
    '08/01/2012 to 14/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
    '15/01/2012 to 21/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 THEN
    '22/01/2012 to 28/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 THEN
    '29/01/2012 to 31/01/2012'
    END
    week,vendor,customer,cost
    FROM report)
    GROUP BY week, vendor, customer
    UNION ALL
    SELECT tw.week,vendor,customer,0
    FROM ( SELECT week,vendor,customer,SUM (cost) cost
    FROM (SELECT CASE
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 THEN
    '01/01/2012 to 07/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 THEN
    '08/01/2012 to 14/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
    '15/01/2012 to 21/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 THEN
    '22/01/2012 to 28/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 THEN
    '29/01/2012 to 31/01/2012'
    END
    week,vendor,customer,cost
    FROM report)
    GROUP BY week, vendor, customer),temp_week tw)
    GROUP BY week, vendor, customer
    ORDER BY vendor, customer, week ;
    with above query i am getting below output:
    with output as(
    select '01/01/2012 to 07/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 500 as cost from dual union all
    select '08/01/2012 to 14/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 200 as cost from dual union all
    select '15/01/2012 to 21/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 0 as cost from dual union all
    select '22/01/2012 to 28/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 0 as cost from dual union all
    select '29/01/2012 to 31/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 0 as cost from dual union all
    select '01/01/2012 to 07/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 330 as cost from dual union all
    select '08/01/2012 to 14/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 370 as cost from dual union all
    select '15/01/2012 to 21/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 300 as cost from dual union all
    select '22/01/2012 to 28/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 0 as cost from dual union all
    select '29/01/2012 to 31/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 0 as cost from dual )
    Clearly I have used cross join. But I want to get same output with some other way. I dont want to use cross join and Union
    please help me in this.

    DUPLICATE!
    SQL Query help.

  • Query on sales analysis

    I have a query to do a sales analysis and look at both inv and credit notes:
    The query runs and pulls out both the inv and credit notes i want it to then deduct the quantity and 'Sales Amt' from the first part any ideas?
    SELECT
    T1.ItemCode, T1.ItemName,  SUM(T0.Price * T0.Quantity) AS turnover,SUM(T0.Quantity) AS QTY,
    Sum(IsNull(T0.LineTotal,0)) 'Sales Amt',
    SUM(IsNull(T0.GrssProfit,0)) 'Gross Profit',
    Case WHEN Sum(Isnull(T0.LineTotal,0)) = 0 THEN 0 ELSE
    SUM(IsNUll(T0.GrssProfit,0))/Sum(Isnull(T0.LineTotal,0)) * 100 END 'Gross Profit %'
    FROM INV1 T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITB T2 ON T2.ItmsGrpCod = T1.ItmsGrpCod INNER JOIN OINV T3 ON T3.DocEntry = T0.DocEntry INNER JOIN OCRD T4 ON T1.CardCode = T4.CardCode INNER JOIN OCRG T5 ON T4.GroupCode = T5.GroupCode
    WHERE T3.DocDate Between [%1] AND [%2]
    GROUP BY T1.ItemCode, T1.ItemName
    UNION ALL
    SELECT
    T1.ItemCode, T1.ItemName, SUM(-T0.Price * T0.Quantity) AS turnover,SUM(-T0.Quantity) AS QTY,
    Sum(IsNull(-T0.LineTotal,0)) 'Sales Amt',
    SUM(IsNull(-T0.GrssProfit,0)) 'Gross Profit',
    Case WHEN Sum(Isnull(-T0.LineTotal,0)) = 0 THEN 0 ELSE
    SUM(IsNUll(-T0.GrssProfit,0))/Sum(Isnull(-T0.LineTotal,0)) * 100 END 'Gross Profit %'
    FROM RIN1 T0 INNER JOIN OITM T1 ON T0.ItemCode = T1.ItemCode INNER JOIN OITB T2 ON T2.ItmsGrpCod = T1.ItmsGrpCod INNER JOIN ORIN T3 ON T3.DocEntry = T0.DocEntry INNER JOIN OCRD T4 ON T1.CardCode = T4.CardCode INNER JOIN OCRG T5 ON T4.GroupCode = T5.GroupCode
    WHERE T3.DocDate Between [%1] AND [%2]
    GROUP BY T1.ItemCode, T1.ItemName

    Try this:
    SELECT T0.[DocNum], SUM(T0.DocTotal) AS 'Total', SUM(T0.U_Total_GP) AS 'Total GP'
    FROM ORDR T0 WHERE T0.[DocDate] =[%0] GROUP BY T0.[DocNum]
    Union ALL
    SELECT count(DocDate), SUM(T0.DocTotal) AS 'Total', SUM(T0.U_Total_GP) AS 'Total GP'
    FROM ORDR T0 WHERE T0.[DocDate] =[%0]

  • User Query - Expanding the Sales Analysis report

    Dear All,
    I have to make a Sales Analysis Report for a client, but groupping by Countries, which is not possible with the built in Sales Analysis Report. I have tried many ways to complete a user query but always failed. I have to aggregate the Sales Invoices, decreased by the amounts on related target Credit Memos (if there are ones) and group by Countries (taken from CRD1.Country).
    Please help me out, if you can.
    Thank you very much,
    Balazs Barta

    Hi
    Please search the forum with Sales Analysis Report .
    Lots of thread are discussed and queries are given,.
    Hope this helps to solve your problem
    Here is one of the thread
    Sales analysis
    Thank you
    Bishal
    Edited by: Bishal Adhikari on Feb 24, 2009 1:20 PM

  • Query to calculate the Sales Analysis on OINV table

    Hi All,
    I have a requirements that will calculate the sales analysis based on A/R Invoice and also considered the Credit Memo applied to Invoice.
    thanks,
    vin

    Hi,
    Try this:
    SELECT T0.CardCode, T0.CardName,
         (SUM(T1.Debit) - sum(T1.Credit)) AS 'Total Sales 2010', ((SUM(T1.Debit) - sum(T1.Credit))/12) AS '2010 Monthly Avg',
         (SUM(T1.Debit) - sum(T1.Credit)) AS 'Total Sales 2011', ((SUM(T1.Debit) - sum(T1.Credit))/Month(GetDate())) AS '2011 Monthly Avg',
         ((sum(Case DATENAME(month,T1.DueDate) when 'January' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'January'
          then T1.Debit else 0 end))) Jan,
         (sum(Case DATENAME(month,T1.DueDate) when 'February' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'February'
          then T1.Debit else 0 end))[Feb],
         (sum(Case DATENAME(month,T1.DueDate) when 'March' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'March' then T1.Debit else 0 end))Mar,
         (sum(Case DATENAME(month,T1.DueDate) when 'April' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'April' then T1.Debit else 0 end))Apr,
         (sum(Case DATENAME(month,T1.DueDate) when 'May' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'May' then T1.Debit else 0 end))May,
         (sum(Case DATENAME(month,T1.DueDate) when 'June' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'June' then T1.Debit else 0 end))Jun,
         (sum(Case DATENAME(month,T1.DueDate) when 'July' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'July' then T1.Debit else 0 end))Jul,
         (sum(Case DATENAME(month,T1.DueDate) when 'August' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'August'
          then T1.Debit else 0 end))Aug,
         (sum(Case DATENAME(month,T1.DueDate) when 'September' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'September'
          then T1.Debit else 0 end))Sep,
         (sum(Case DATENAME(month,T1.DueDate) when 'October' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'October'
          then T1.Debit else 0 end))Oct,
         (sum(Case DATENAME(month,T1.DueDate) when 'November' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'November'
          then T1.Debit else 0 end))Nov,
         (sum(Case DATENAME(month,T1.DueDate) when 'December' then T1.Credit  else 0 end)-sum(Case DATENAME(month,T1.DueDate) when 'December'
          then T1.Debit else 0 end)) Dec
    FROM  OCRD T0
            LEFT JOIN JDT1 T1 ON T1.ShortName = T0.CardCode
            AND Year(T1.Duedate) = 2011   AND T1.TransType in ('13','14')
    WHERE T0.CardType = 'C'
    Group By DATENAME(month,T1.DueDate), T0.CardCode, T0.CardName
    Thanks,
    Neetu

Maybe you are looking for