| Author |
Topic |
|
anujpratap84
Starting Member
45 Posts |
Posted - 2011-09-28 : 02:56:29
|
| Hi All,I have a table with some no of columns.I want to inert a row on top of the table witch contains the sum of each column.Ex: Month DEF TDN CLX 1 23 55 6 2 22 5 4The resultant table will be likeMonth DEF TDN CLX Total 45 60 10 1 23 55 6 2 22 5 4Please help Thanks in advanceAnuj Pratap Singh |
|
|
vmvadivel
Yak Posting Veteran
69 Posts |
Posted - 2011-09-28 : 03:16:00
|
| Make use of ROLLUP in SQL Server.Best RegardsVadivelhttp://vadivel.blogspot.com |
 |
|
|
anujpratap84
Starting Member
45 Posts |
Posted - 2011-09-28 : 03:21:01
|
Thanks for quick reply..Can you give an example based on my senerio..quote: Originally posted by vmvadivel Make use of ROLLUP in SQL Server.Best RegardsVadivelhttp://vadivel.blogspot.com
Anuj Pratap Singh |
 |
|
|
vmvadivel
Yak Posting Veteran
69 Posts |
Posted - 2011-09-28 : 06:22:35
|
| Create table tblTest11( [Month] int, DEF int, TDN int, CLX int)GOINSERT INTO tbltest11SELECT 1, 23, 55, 6 UNION ALLSELECT 2, 22, 5, 4GO--SolutionSELECT ISNULL(CONVERT(VARCHAR,[Month]),'Total') AS [Month], CONVERT(VARCHAR,SUM(DEF),1) AS [DEF], CONVERT(VARCHAR,SUM(TDN),1) AS [TDN], CONVERT(VARCHAR,SUM(CLX),1) AS [CLX]FROM tblTest11GROUP BY [Month] WITH ROLLUP ORDER BY [Month]Best RegardsVadivelhttp://vadivel.blogspot.com |
 |
|
|
anujpratap84
Starting Member
45 Posts |
Posted - 2011-09-29 : 01:43:19
|
Thanks a alot..It's working....quote: Originally posted by vmvadivel Create table tblTest11( [Month] int, DEF int, TDN int, CLX int)GOINSERT INTO tbltest11SELECT 1, 23, 55, 6 UNION ALLSELECT 2, 22, 5, 4GO--SolutionSELECT ISNULL(CONVERT(VARCHAR,[Month]),'Total') AS [Month], CONVERT(VARCHAR,SUM(DEF),1) AS [DEF], CONVERT(VARCHAR,SUM(TDN),1) AS [TDN], CONVERT(VARCHAR,SUM(CLX),1) AS [CLX]FROM tblTest11GROUP BY [Month] WITH ROLLUP ORDER BY [Month]Best RegardsVadivelhttp://vadivel.blogspot.com
Anuj Pratap Singh |
 |
|
|
|
|
|