You must Sign In to post a response.
  • Category: SQL Server

    How to Group Weekwise in SQL

    Hi to all

    i need to generate weekwise sales REPORT FOR THE particular month.

    in this case user select the month name,item name only then i will generate the report in following format

    for eg month name July , item Name XYZ

    then i needs to generate report in the following format

    Week Duration Qty Amount
    1 01-Jun to 07-Jun 10 10.00
    2 08-Jun to 14-Jun 15 15.00
    3 15-Jun to 21-Jun 8 8.00
    4 22-Jun to 28-Jun 4 4.00
    5 29-Jun to 30-Jun 13 13.00

    How can i write the Query in SQL.

    if any one know the answer let me know..

    Thanks & Regards

    Saravana Perumal.N
  • #747335
    Use the below SQL Query to generate week wise Report

    SELECT DATEPART(wk, dates) AS WeekNumber,
    CAST(MIN(dates) AS CHAR(10)) + ' to '
    + CAST(MAX(dates) AS CHAR(10)) AS [Duration],
    SUM(amount) AS [Amount]
    FROM qmaster
    WHERE item = 'AA'
    GROUP BY DATEPART(wk, dates)

  • Sign In to post your comments