How to get Quaterly Data from the Query

  • Hi All,

    I want to select the data from the table in Quarterly

    i have the following query but it is suming all the months and giving

    in following query i want to show sum of 01 to 03months in row and o4 to 06 in one row....like

    that if i give 200101 to 200112...it has to give me 4 quaters....how to do that..

    select CONVERT(CHAR(4),period,112), sum(composite)

    from cdh_price_gap

    where CONVERT(CHAR(6),period,112) between '200101' and '200106'

    group by CONVERT(CHAR(4),period,112)

    order by CONVERT(CHAR(4),period,112)

    i used to convert to compare the date in this formate 200101 thats it...

    thanks

  • Hi,

    why not use a combination of DATEPART(quarter, <your_field>), and sum

    like

    SELECT DATEPART(quarter, period) AS Quartal, Sum(composite) as Summe

    FROM ....

    GROUP BY DATEPART(quarter, period)

    ORDER BY ...

    This assumes that period is a datetime field

    Cheers,

    Frank

    Edited by - a5xo3z1 on 04/10/2003 09:11:30 AM

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

Viewing 2 posts - 1 through 1 (of 1 total)

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