Solved

Simple current month sales

Posted on 2014-03-18
2
335 Views
Last Modified: 2014-03-18
I have a simple table with orders. I have a OrderAmount field that I want to sum based on the current month. There is also an OrderDate that has a Date and time stamp. Also looking for a ytd summation. I'm trying to avoid making a Calendar Table.
0
Comment
Question by:Southern_Gentleman
2 Comments
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 500 total points
ID: 39938192
Not sure if this is exactly what you're looking for...expected output would be useful.

SELECT
   (
      SELECT SUM(OrderAmount)
      FROM Orders
      WHERE YEAR(OrderDate) = YEAR(GETDATE())
   ) AS YTD,
   (
      SELECT SUM(OrderAmount)
      FROM Orders
      WHERE YEAR(OrderDate) = YEAR(GETDATE())
         AND MONTH(OrderDate) = MONTH(GETDATE())
   ) AS MTD
0
 

Author Closing Comment

by:Southern_Gentleman
ID: 39938244
Cool, Thanks a bunch
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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 the fundamental information of how to create a table.

829 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