Solved

Simple current month sales

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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

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.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.

734 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