Solved

SQL view totals

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

691 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