Home Forums SQL Server 2008 T-SQL (SS2K8) Getting Total Count for each month based on the Start and End Date RE: Getting Total Count for each month based on the Start and End Date

  • You could add the MONTH and YEAR functions or a CONVERT to group by.

    SELECT RIGHT( CONVERT(char(11), FlightDate, 113), 8) Month,

    COUNT (PaxNum) as TotalPassengersCount

    FROM dbo.FlightDetails

    WHERE FlightDate BETWEEN '1/1/2013' and '1/31/2013'

    GROUP BY RIGHT( CONVERT(char(11), FlightDate, 113), 8);

    PS. You can change the Month format

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2