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 2000 Forums
 Transact-SQL (2000)
 Including summary data with sums

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2004-12-02 : 08:23:37
bharat writes "Hi I have a table which has in addition to others two columns "budget" and "description". The table has table id which is 14 digit number stored as string, It also have Account Type which can have values of 'H', 'C', 'S', 'L'.

'H' represents a fund and 'C' are departments under the fund and 'S' is subdepartment under department and 'L' is line items under 'S'. The total of L's comes up to S, total of S's comes up to C and total of C's come up to H. there are 41 unique 'H' under which there are C, S and L's. the description column has the name of each fund, department, subdepartment and line items needless to say they are all unique.

I want to be able to show totals by account type ie. by 'H', 'C', 'S' and 'L'. I know I can use the Sum function which will total all 'L's' under an 'H' roll it up and give me a sum however it will not extract the description from the corrosponding 'H' description column to display against the sum. To be more clear if i sum by acct type = 'H' I need to see the following:

ID Sum Description
12343567890000 10000 CURRENT ACCOUNT

they are stored as

ID acct_type budget Description
12343567890000 H 0.00 CURRENT ACCOUNT
12343567891100 C 0.00 Curr Acc --Uniform
12343567891111 S 2500 School Uniforms
12343567891112 S 2500 Mason Uniforms
12343567891200 C 0.00 Curr Acc--Outdoor
12343567891211 S 5000 Wall repair

I want to add all the 'S' under each 'H' display the ID and the description (Current Account).
any stored procedure or anything else to do this? I have not dound anything."
   

- Advertisement -