?
Solved

SQL view totals

Posted on 2011-03-02
2
Medium Priority
?
311 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
[X]
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
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Suggested Courses

741 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