Solved

Simple current month sales

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

 Database Backup and Recovery Best Practices

Join Percona’s, Architect, Manjot Singh as he presents Database Backup and Recovery Best Practices (with a Focus on MySQL) on Thursday, July 27, 2017 at 11:00 am PDT / 2:00 pm EDT (UTC-7). In the case of a failure, do you know how long it will take to restore your database?

Question has a verified solution.

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

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…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

615 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