Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 inserting subtotals

Author  Topic 

katbrennan
Starting Member

1 Post

Posted - 2011-03-11 : 14:17:42
Hello,

Could someone please tell me how to calculate a subtotal? I have two tables, one with transactional data and account numbers, and the other table with line numbers, line descriptions and accout numbers. The tables are joined on account number.

What I want is to pull a monthly amount and then group certain line numbers together and have subtotals. I want my result set to look like this:

1. Line Description 1 100.00
2. Line Description 2 400.00
3. Line Description 3 200.00
4. Subtotal Revenue 700.00
5. Line Description 4 500.00
6. Line Description 5 100.00
7. Subtotal Expenses 600.00
and so on...

I am about to get the monthly amounts for the regular lines, just not for the subtotals. So what I would like to do would be something like this:

If line number = 4 then sum lines 1, 2, 3
If line number = 7 then sum lines 5, 6

Is this possible?

Thanks.
   

- Advertisement -