SUM a range of records from a fixed DATE in the DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • miguelleugim
    New Member
    • May 2007
    • 2

    SUM a range of records from a fixed DATE in the DB

    I need to SUM a range of records from a fixed DATE in the DB, the fixed date is 'A.relationship _from' and I have to SUM 90 days from that DATE

    SELECT A.AGENT_CODE,T. AGENT_ID,Count (T.TRANS_ACTION _ID), Sum (T.amt_dls),A.r elationship_fro m

    FROM TRANSACTION_TAB LE T,
    AGENT A (NOLOCK)


    WHERE T.agent_id = A.agent_id

    AND t.DOT >= '2007-05-20'

    AND promoter_region = 'SC'
    AND promoter_center = '4'
    --AND T.AGENT_ID = '460'

    GROUP BY T.AGENT_ID,A.ag ent_CODE,A.rela tionship_from

    ORDER BY T.AGENT_ID

    ----

    This is a result but not from the date I would like :

    TX-544 544 2 950.0000 2006-09-26 00:00:00.000
  • almaz
    Recognized Expert New Member
    • Dec 2006
    • 168

    #2
    [CODE=sql]SELECT A.AGENT_CODE,T. AGENT_ID,Count (T.TRANS_ACTION _ID), Sum (T.amt_dls),A.r elationship_fro m

    FROM TRANSACTION_TAB LE T inner join
    AGENT A (NOLOCK) on T.agent_id = A.agent_id
    WHERE
    t.DOT between A.relationship_ from and dateadd(dd, 90, A.relationship_ from)
    AND promoter_region = 'SC'
    AND promoter_center = '4'
    --AND T.AGENT_ID = '460'

    GROUP BY T.AGENT_ID,A.ag ent_CODE,A.rela tionship_from
    ORDER BY T.AGENT_ID[/CODE]

    Comment

    • miguelleugim
      New Member
      • May 2007
      • 2

      #3
      It works fine, Thanks !!

      Comment

      Working...