Question : Adding a row of totals

Hi experts,

I have a query which produces some rows as in:

col1   col2   col3   col4
5          5        4        5
6          2        1        3
7          4        3        2

What I want to do is to add another row which contains the total of col1 col2 col3 and col4 eg:

col1   col2   col3   col4
18        11       8      10

How would I achieve this with just 1 query?

Answer : Adding a row of totals

Example
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
declare @sometable table (
  id int identity, 
  col1 int,
  col2 int,
  col3 int,
  col4 int
)

insert into @sometable
select 1, 2, 3, 4 union all
select 5, 6, 7, 8
  
; WITH CTE AS  (
SELECT col1, col2, col3, col4
FROM @sometable
)
SELECT * from CTE
union all 
select SUM(col1), SUM(col2), SUM(col3), SUM(col4)
FROM CTE
Random Solutions  
 
programming4us programming4us