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 2000 Forums
 Transact-SQL (2000)
 Datediff between two rows

Author  Topic 

kmartin
Starting Member

5 Posts

Posted - 2008-04-04 : 09:21:14
I have the table:

Item |Into |Out |Diff
------------------------------------------------------------------
001 2008-01-05 00:00:00.000 2008-01-10 00:00:00.000 5
001 2008-01-11 00:00:00.000 2008-01-20 00:00:00.000 9
001 2008-01-21 00:00:00.000 2008-01-27 00:00:00.000 6
001 2008-02-27 00:00:00.000 2008-03-03 00:00:00.000 5
001 2008-03-05 00:00:00.000 2008-03-12 00:00:00.000 7
099 2008-01-30 00:00:00.000 2008-01-30 16:00:00.000 0
099 2008-02-06 00:00:00.000 2008-02-08 00:00:00.000 2
099 2008-02-17 00:00:00.000 2008-02-19 00:00:00.000 2

What I would like is difference between an 'Out' and an 'Into', such as... row one has an Out of 1/10/08 and row two has an Into of 1/11/08, a difference of 1 day, I can't seem to get another column to properly show this information.

kmartin
Starting Member

5 Posts

Posted - 2008-04-04 : 09:52:29
Hooah, I got it. Please feel free to close this thread
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-04-04 : 09:58:55
quote:
Originally posted by kmartin

Hooah, I got it. Please feel free to close this thread


Post your solution so that others can know

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kmartin
Starting Member

5 Posts

Posted - 2008-04-04 : 11:30:08
quote:
Originally posted by madhivanan

quote:
Originally posted by kmartin

Hooah, I got it. Please feel free to close this thread


Post your solution so that others can know

Madhivanan

Failing to plan is Planning to fail



Created a temp table with a new new column and updated the column with:
datediff(day, retrn_dt, (select top 1 drop_off_dt from #temp2 where t2.retrn_dt <= drop_off_dt order by drop_off_dt))
Go to Top of Page
   

- Advertisement -