Solved

SQL Server Subquery

Posted on 2013-06-12
3
255 Views
Last Modified: 2013-06-12
I need some help restructuring this query so it does not bring in TotalSales that = 0. I end up with gaps in the data I would like to eliminate.



SELECT			pd.StoreID, st.ShortName, pd.Hour, ROUND(SUM(pd.TaxableSales) + SUM(pd.TaxExemptSales), - 2) AS TotalSales

FROM            POSDataDetailByHour AS pd 
				INNER JOIN FiscalDatesByDay AS fd ON fd.TransactionDate = pd.TransactionDate 
				INNER JOIN Stores AS st ON st.StoreID = pd.StoreID

WHERE			(pd.TransactionDate BETWEEN '6-11-13' AND '6-12-13')

GROUP BY		 pd.StoreID, st.ShortName, pd.Hour

Open in new window

0
Comment
Question by:dk04
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
Comment Utility
SELECT pd.StoreID, st.ShortName, pd.Hour, 
    ROUND(SUM(pd.TaxableSales) + SUM(pd.TaxExemptSales), - 2) AS TotalSales
FROM POSDataDetailByHour AS pd INNER JOIN 
    FiscalDatesByDay AS fd ON fd.TransactionDate = pd.TransactionDate INNER JOIN 
    Stores AS st ON st.StoreID = pd.StoreID
WHERE (pd.TransactionDate BETWEEN '6-11-13' AND '6-12-13')
GROUP BY pd.StoreID, st.ShortName, pd.Hour
HAVING ROUND(SUM(pd.TaxableSales) + SUM(pd.TaxExemptSales), - 2) <> 0

Open in new window

0
 
LVL 8

Expert Comment

by:didnthaveaname
Comment Utility
try:

SELECT			pd.StoreID, st.ShortName, pd.Hour, ROUND(SUM(pd.TaxableSales) + SUM(pd.TaxExemptSales), - 2) AS TotalSales

FROM            POSDataDetailByHour AS pd 
				INNER JOIN FiscalDatesByDay AS fd ON fd.TransactionDate = pd.TransactionDate 
				INNER JOIN Stores AS st ON st.StoreID = pd.StoreID

WHERE			(pd.TransactionDate BETWEEN '6-11-13' AND '6-12-13')

GROUP BY		 pd.StoreID, st.ShortName, pd.Hour
having
    ROUND(SUM(pd.TaxableSales) + SUM(pd.TaxExemptSales), - 2) > 0

Open in new window

0
 

Author Closing Comment

by:dk04
Comment Utility
Thank you. It worked great!
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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

728 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

14 Experts available now in Live!

Get 1:1 Help Now