Hari prasad 101405


i want result to be in the required format given below:

here is the result

column A

----------------

5

7

10

14

22

30

....

i want output to be in this form with a single sql statement:

column A column B

---------------- ----------------

5 2(difference b/n the current record and the next record)

7 3

10 4

14 8

22 8

30 0

can any one plz post the query which gives the above kind of result..

thnx in advance..




Re: Help plz - need query to get the following kind of output

CetinBasoz


with myTable as
 ( select columnA, row_number() over (order by columnA) as rowno from tableA )
 
select t1.columnA, isnull(t2.columnA - t1.columnA ,0) as columnB
   
from myTable t1
    
left join myTable t2 on t1.rowno = t2.rowno-1






Re: Help plz - need query to get the following kind of output

Hari prasad 101405

but row_number() is not there in sql server 2000.

i want to run this query in sql server 2000






Re: Help plz - need query to get the following kind of output

CetinBasoz

And who knows that you're talking about 2000.

select t1.columnA,
( select min(columnA) from myTable t2 where t2.columnA > t1.columnA ) - t1.columnA as columnB
from myTable t1
order by t1.columnA





Re: Help plz - need query to get the following kind of output

Hari prasad 101405

sorry CetinBasoz i forgot to mention about that..

and thank u so much for ur help.. so long i hv been struggling for this query.. thank u very much..

bye