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

    sql query to sort data by month or date or year wise

    Hi,

    Could you please tell me how can i sort data in database table by month wise or date wise or year wise?



    Thanks,
    Myself
  • #310628
    Hi,

    Try this query,

    Select cast(month(billdate) as char(2))+'-'+cast(year(billdate) as char(5)) as monthwise,
    qty=sum(qty),Amount=sum(qty*rate)
    from sales
    group by month(billdate),year(billdate)

    The above query will gives monthwise sales. Alter the query for ur need.
    I Hope it helps u lot.

    Happy Coding.

    Regards,
    S.Shankaran.

  • #310661
    Select columnname1,column2 from tablename
    group by month(date),year(date)

    The above query will gives monthwise sales. Alter the query for ur need.
    I Hope it helps u lot.

  • #311882
    rohitash yadav has given the correct and simple solution.
    U can follow the second one.


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.