Posted by: NEPAL_SACH22 May 3, 2010
SQL server roll-up function help
Login in to Rate this Post:     0       ?        

Try this out the_hareeb.


select ID,name,Category, SUM(Children)as Total_Children


from myBaseTable


group by ID,name,Category with rollup

 

here is another one that gives you exactly what you wanted:

Select Id, Name, Category=Case when ig=1 then 'SUBTOTAL' else Category end, Children

FROM

(

Select

Id, Name, Category, Children=Sum(Children),

ig=Grouping(Id), ng=Grouping(Name), cg=Grouping(Category)

From myBaseTable

Group by rollup (category,Id,Name)

) Grouped

Where ng = ig and cg <> 1


Thanks!

Last edited: 03-May-10 10:19 PM
Read Full Discussion Thread for this article