SQL Server Over Partition

  • I have added the code that was missing. Column A is not a dollar figure but a limit payed out. When column A is 0 it indicates a limit removed or a limit not removed. In the example given there is no negative limits.
    The calculations are flags when to select records. when column b and c are 1 select the record. In essence select the first record when the TT value changes. In the example given the record is not being selected because the value is not reset to 1. this occurred because there are 2 TT: C within the PI: 2800 and m: 4. In the example given there are no consecutive TT and therefore all records need to be selected. A value is cancelled by a TT: C. A value is charged by TT: P, R.   

    sum (case when A <> 0 then 1 else 0 end)

    over (PARTITION BY A.PI,A.M, TT )

    order by A.date) as b


      

    --Counts zero records for column A
    select A.PI, A.m, A.Date, TT,  A.A
          sum (case when A.A <> 0 then 0 else 1 end) --counts zero0
      Over (PARTITION  BY  A.PI, A.m, A.TT order by  A.Date) as a,
     
    --Counts records with values in Column A 
    --The counts need to reset when TT changes.
       sum (case when A.A <> 0 then 1  else 0 end)
      Over (PARTITION  BY  A.PI, A.m, A.TT order by  A.Date) as b,     
    --Counts records with values and determines if the record is a negative transaction
    --The only difference in column c is when A has a 0. it needs to determine if a negative --transaction or not a negative transaction
       sum (case when A.A <> 0 then 1 when A.A Issue is = 0 and  TT = 'E' then 1 else 0 end)   Over (PARTITION  BY  A.PI, A.m, A.TT order by  A.Date) as c

    In the spreadsheet I need the columns j,k,l getting f,g,h note if tt changes set to 1

  • Welcome aboard!
    since you appear to be new here, you owe it to yourself to read this article: 

    Forum Etiquette: How to post data/code on a forum to get the best help

    Help us help you by including all the information we need to help - the article explains how to do that.  Many people here are leery of downloading documents to replicate your setup... so post T-SQL here instead. Then we can help you.

    Thanks!

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

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