Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2012

    Unanswered: SQL Server 2008 R2


    I need some assistance with my SQL code. I am summing the amount field based on the department....which I have not problem doing. So, I now have 3 columns in my report. Department, Account#, and the amount....grouped by the department from Table 1.

    I am trying to add 2 other account #'s that do not exists in Table 1. I declared the values but my code is just not working for me.

    The ultimate idea is to add the 2 account #'s to the table and calculate 13% of one acct# and 87% of the other acct% based on the total from table 1.

    I really need help.....If possible.

    thank You,

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    Please post an example of the output that you want... I can think of at least three different ways to interpret what you've requested, and with three different targets I'm pretty sure that I can't "hit the bulls-eye" on what you actually want!

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Nov 2012

    SQL Help

    I have the table below using this code:

     SELECT [Department], [Dept Description], 
    (cast ( sum([Amount Charged]) as decimal (10,2))) as Amount
    FROM dbo.table1
    Group by [Department],[Dept Description]
    Results from above code:
    Click image for larger version. 

Name:	Capture66.JPG 
Views:	2 
Size:	41.2 KB 
ID:	15972

    I need to be able to sum the “Amount” column, add 2 additional Department & Dept Description that is not in dbo.table1 and calculate 13% of total and 87% of total.

    So, the final result will look like:
    Click image for larger version. 

Name:	Capture201.JPG 
Views:	3 
Size:	51.8 KB 
ID:	15973

    The calculation is:

    For (Paper) subtotal/0.040 * 0.007

    For (lease/Maintenance) subtotal/0.040 * 0.035

    • The last 2 items are not in TABLE1…..need to be added. I’m just not sure how to do it with the calculation.

  4. #4
    Join Date
    Jan 2003
    Provided Answers: 17
    Is the final result shown what the display layer will look like? This is not something I would do in SQL Server. This should be something done in either Excel, or Reporting Services. Connect Excel to SQL Server, and retrieve the first data set, then the rest will be formulas in Excel.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts