Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 recursive non null difference

Author  Topic 

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2007-05-21 : 15:36:05
Hi all,
I'll try to explain my problem:

create table #temp (tempid int, Cycle int, Number int)

insert into #temp
select 1,0,12 union all
select 1,1,NULL union all
select 1,2,24 union all
select 2,0,12 union all
select 1,3,40 union all
select 2,1,23 union all
select 2,2,NULL


I am trying to get the result set as

Number_diff tempid
16 1
12 1
11 2

for tempid =1 , number of cycle3 - number of cycle 2
for tempid =1 , number of cycle2 - number of cycle 0 as number of cycle 1 is null


Any pointers are much appreciated.

Thanks for the efforts.

~Harshal

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-05-21 : 15:42:06
I have no idea what you are looking for. It might be helpful if you carefully explain EXACTLY what you need.

- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2007-05-21 : 15:52:00
quote:
Originally posted by jsmith8858

I have no idea what you are looking for. It might be helpful if you carefully explain EXACTLY what you need.

- Jeff
http://weblogs.sqlteam.com/JeffS




Sorry..

I want the difference between not null [Number] for each tempID starting with descending cycle.

for example in #temp for tempid = 1
select a.number- b.number
from #temp a,#temp b
where a.tempid = b.tempid
and a.cycle= 3 and b.cycle=2

Does this make sense?

thanks for trying to help.
Go to Top of Page
   

- Advertisement -