Compute column

  • hi all

    how to calculate Total value below example

    ID NameValueTotal Value

    1x2020

    2y1030

    3z3060

    4a50110

    5b40150

    6c80230

    i want to add total value like fibonacci series

    first row- [Total Value] column display value of id=1

    2 row - [Total Value] column display value of ID 1,2

    3 row - [Total Value] column display value of ID 1,2,3

    .............etc

    Prasad.N
    Hyderabad-India.

  • Sounds like a running totals solution

    http://www.sqlservercentral.com/articles/T-SQL/68467/

  • hi all,

    i got answers

    declare @table table (rid int, tot int)

    insert into @table

    select 1,10

    union

    select 2,20

    union

    select 3,30

    union

    select 4,40

    union

    select 5,50

    union

    select 6,70

    SELECT rid,tot,

    (SELECT SUM(tot)

    FROM @table F1

    WHERE F1.rid <= F2.rid and rid>2) AS b

    FROM @table F2 --where PdaId=38

    where rid>2

    Prasad.N
    Hyderabad-India.

  • That is bad one. Triangular-joins are performance killers in this case.

    My advice is to read the article pointed in the first reply.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • Hi Prasad,

    Please try this SELECT statement below:

    select t.ID,t.name,t.value,(select sum(s.value) from T1 s where s.id<=t.id)

    from T1 t

    Regards,
    Ravi.

Viewing 5 posts - 1 through 4 (of 4 total)

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