Solved

SQL view totals

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
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.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

726 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