August 31, 2010 at 6:44 pm
After doing all the joins my final result set is something like this
This has records description, count column
Rerecords Description Count
Bank Records ------- 50
Hospital Records ----100
I need one more row where the total records which is the sum of bank records and hospital records ie here 150.
Rerecords Description ----Count
Bank Records ------50
Hospital Records -------100
Total Records ---------150
how to write query for this?
thanks
August 31, 2010 at 7:06 pm
Lutz already showed you how to do this over here. Especially relevant is the ROLLUP clause of the SELECT statement.
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
August 31, 2010 at 9:23 pm
I tried to do roll up but i could not get the result what i needed.
Let me know if theres is any way i can do it.
Thanks
September 1, 2010 at 12:04 am
Try this:
SELECT (CASE WHEN RecordDescription IS NULL THEN 'Total records' ELSE RecordDescription END) as Records, SUM(Count) from Table1 GROUP BY RecordDescription WITH ROLLUP
September 1, 2010 at 12:22 am
Hi Tarun Jaggi,
I have converted the result set into pivot table hence problem solved. Thank you very much for your reply.
THnaks
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply