Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

SQL view totals

Posted on 2011-03-02
2
285 Views
Last Modified: 2012-05-11
I am running the attached code. At the bottom i want to add a totals column.

How can i do this? I have also attached a picture to show the output of the ran code.

SELECT     DATEDIFF(d, CONVERT(DATETIME, '2010-07-01 00:00:00', 102), dbo.tbl_main.Docs_Sent1) / 7 + 1 AS Week, 
                      COUNT(DISTINCT CASE WHEN [order type] = 'inbound' THEN tbl_main.reference ELSE NULL END) AS [Inbound Orders], 
                      COUNT(DISTINCT CASE WHEN [order type] = 'Outbound' THEN tbl_main.reference ELSE NULL END) AS [Outbound Orders], 
                      SUM(CASE WHEN [edmake] = 't4' THEN '1' ELSE 0 END) AS [t4], 
                      SUM(CASE WHEN [edmake] = 't41' THEN '1' ELSE 0 END) AS [t41], 
                      SUM(CASE WHEN [edmake] = 'm4' THEN '1' ELSE 0 END) AS [m4], 
                      SUM(CASE WHEN [edmake] = 'm41' THEN '1' ELSE 0 END) AS [m41], SUM(dbo.tbl_table.Commband) 
                      AS Commband
FROM         dbo.tbl_table INNER JOIN
                      dbo.tbl_main ON dbo.tbl_table.Reference = dbo.tbl_main.Reference
GROUP BY DATEDIFF(d, CONVERT(DATETIME, '2010-07-01 00:00:00', 102), dbo.tbl_main.Docs_Sent1) / 7 + 1

Open in new window

activitylog.jpg
0
Comment
Question by:CaptainGiblets
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35016269
you could add
WITH ROLLUP
after the GROUP BY ..
0
 
LVL 6

Author Closing Comment

by:CaptainGiblets
ID: 35016278
thanks :)
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
LTrim & Double Space Correction 5 39
where to find DTS instalation package for sql 2014 64 bit 3 10
SQLCMD Syntax 2 13
SQL Recursion 6 16
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question