Display Last 3 months report in below format

  • Hello,
    I need to display sales report in following pattern

    Category  Feb   Jan  Dec  Total
    Fabric       200  200  300   700
    NonFabric 100 200   400  700
    Total          300 400  700   1400

    I need to display Last three month sales report along with the total.
    Kindly help me to build logic for the same.
    Regards
    Shirish Phadnis

  • WHERE [SaleDate]>DATEADD("m",-3,GETDATE()) ?
    https://docs.microsoft.com/en-us/sql/t-sql/functions/dateadd-transact-sql

  • Thank you for reply.
    But I need to display month name dynamically.
    It should be last 3 months from current month
    Please advise.

  • shirish1987 - Wednesday, March 14, 2018 11:26 PM

    Thank you for reply.
    But I need to display month name dynamically.
    It should be last 3 months from current month
    Please advise.

    How are you planning to display the information?   In an SSRS report?  If you try to name the columns dynamically, SSRS won't be able to use the query after a month, as the column names would have changed.   If it's always going to be a manual query, then dynamic column names would be okay.   Indicate which scenario you need and someone can do a much better job of helping you.

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • Hello Steve,

    I am not going to display result using SSRS report.
    I need to return result from sql query in the format that I have shared.
    In this moth name would be dynamic (Need to display last 3 month name)
    Please advise.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply