Home Forums SQL Server 7,2000 T-SQL Nested select statements / running total RE: Nested select statements / running total

  • I am not quite sure how the data looks like but here is a wild guess

    select 

           BLOCK_ID

         , DENSITY

         , AVG_THICK

         , BLOCK_SIDE

     , (case when BLOCK_SIDE ='top' then 23 else 0 end)

      - (case when BLOCK_SIDE ='top' then 1 else -1 end) * 

        (select sum(AVG_THICK)

         from dbo.THICKNESS_TABLE y

          where y.[TIME]  <= x.[TIME]

          and y.BLOCK_ID = x.BLOCK_ID)

      as running_total

    from dbo.THICKNESS_TABLE x

    where BLOCK_ID like [conditional parameter]

    group by BLOCK_ID, DENSITY, AVG_THICK, BLOCK_SIDE 

    I assumed BLOCK_SIDE  can only be 'top' or 'bottom', right?

    hth


    * Noel