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)
 DATE DIFFERENCE

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-01-19 : 10:54:50
SONALI writes "Hi
I have a schema like this..

col A col b colc col d
1 1 1-1-2007 -
1 2 2-2-2007 30 days
1 3 2-10-2007 8 days
2 1 1-3-2007 -
2 2 3-3-2007 2 days

how to compute the col d where i hv to show date diff from the last avaialble day?

any help is appreciated:-)"

nr
SQLTeam MVY

12543 Posts

Posted - 2007-01-19 : 11:24:21
select t1.col2 - t2.cold
from tbl t1
join tbl t2
on t2.cold = (select max(t3.cold) where t3.col2 > t1.cold)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -