Solved

SQL view totals

Posted on 2011-03-02
2
257 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 142

Accepted Solution

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

Author Closing Comment

by:CaptainGiblets
Comment Utility
thanks :)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Counts 11 39
SQL Server memory Issue 7 73
Azure SQL DB? 3 12
SQL Stored Procedure insert running but not inserting record 40 26
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.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now