Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    176

    Unanswered: Calculating MTD and YTD in SQL

    Hi all,

    I have a list of transactions with the date and amount fields. I would like to calculate MTD and YTD values from these amounts to display in my report.

    Assuming the current time period is Feb'08 I need to populate MTD and YTD with the values indicated below.

    Date.......................Amount...MTD...YTD
    1/10/2008.................10..............0........10
    1/11/2008.................20...............0........20
    2/10/2008.................30...............30.......30


    How do I accomplish populating MTD and YTD columns in the above table?

    Thanks

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    You don't populate those columns in the table, you derive the value at run-time (i.e. calculate it in a select statement).

    How is MTD 0 at any point?

    If you can provide more comprehensive sample data and let us know what version of SQL Server you're working with, we'll be in a better position to help.
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •