locked
sum data of every month RRS feed

  • Question

  • User639567535 posted

    i try this

     

      select tblRV.OwnerName,
        sum(convert(int,MA)) from tblRV
        inner join tblReg on tblReg.RID=tblRV.RID
        where
        tblReg.StartDate>='2015-07-01 00:00:00.000' and
        tblReg.EndDate<='2015-07-31 23:59:59.000' and
        
        tblRV.RegNo='486' and
        tblReg.Region in ('paris','uk')
        group by
        ownername
    



    this shows me only july data sum whereas i want all 12 month and their and sum of MA according to the month i.e.

    Month      total
     Jan           234
     Feb           345
     March         34
    .....
    Dec            123

    any solution

    Monday, August 22, 2016 4:58 PM

Answers

  • User-286291038 posted

    Hi,

    If month is a column in your table, you can try grouping by month column and removing the filter condition for the StartDate,

    tblReg.StartDate>='2015-07-01 00:00:00.000' and
        tblReg.EndDate<='2015-07-31 23:59:59.000' and
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 22, 2016 5:07 PM
  • User77042963 posted
    select  datename(month,blReg.StartDate) ,
        sum(convert(int,MA)) from tblRV
        inner join tblReg on tblReg.RID=tblRV.RID
        where
        tblReg.StartDate>='2015-01-01 00:00:00.000' and
        tblReg.EndDate<'2016-01-01 00:00:00.000' and    
        tblRV.RegNo='486' and
        tblReg.Region in ('paris','uk')
        group by  datename(month,blReg.StartDate)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 22, 2016 8:04 PM

All replies

  • User-286291038 posted

    Hi,

    If month is a column in your table, you can try grouping by month column and removing the filter condition for the StartDate,

    tblReg.StartDate>='2015-07-01 00:00:00.000' and
        tblReg.EndDate<='2015-07-31 23:59:59.000' and
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 22, 2016 5:07 PM
  • User77042963 posted
    select  datename(month,blReg.StartDate) ,
        sum(convert(int,MA)) from tblRV
        inner join tblReg on tblReg.RID=tblRV.RID
        where
        tblReg.StartDate>='2015-01-01 00:00:00.000' and
        tblReg.EndDate<'2016-01-01 00:00:00.000' and    
        tblRV.RegNo='486' and
        tblReg.Region in ('paris','uk')
        group by  datename(month,blReg.StartDate)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 22, 2016 8:04 PM
  • User639567535 posted

    no there is no month there is start date and end date

    Tuesday, August 23, 2016 4:29 AM