Need help in SUM query

  • Hi

    My table data is as below.

    YEARPERIODIDCONTNBRNet_Transaction_Amount
    2006619863249.44
    2006719863249.44
    2006819863249.44
    2006919863249.44
    20061019863249.44
    20061119863249.44
    20061219863249.44
    2007119863249.44
    2007219863249.44
    2007319863249.44
    2007419863249.44
    2007519863249.16

    I need the sum of Net_Transaction_Amount below 2007 year and period 3

    I am writing the query as below.

    SELECT

    CONTNBR, SUM(Net_Transaction_Amount) AS UnpaidRecognizeupto2006

    FROM

    dbo.SVC6040PV

    WHERE

    (YEAR1 <= 2007 and PERIODID <= 3)

    and

    CONTNBR

    = '0000019178'

    GROUP

    BY CONTNBR

    In the above quiery 2006 year above PERIODID 3 is not considering,

    how to calculate sum Below Year 2007 and Period 3, sum should include 2006 year and all periods of 2006 year.

    Please let me know, how to do this.

    Thx

    Vijji

     

  • ....where cast(year1 as char(4))+right('00'+cast(periodid as varchar(2)),2)<='200703')

     

    OR

    ...Where (year1<2007 OR (year1=2007 AND periodid<=3))

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Hi Matt Miller

    Thank you so much, it is working.

    Thx

    Vijji

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

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