Solved

Simple current month sales

Posted on 2014-03-18
2
330 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
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 extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

707 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