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
 SQL Server Administration (2000)
 Need help

Author  Topic 

AKP2008
Starting Member

45 Posts

Posted - 2009-01-05 : 04:24:58
hi,

I need to generate an incremental column.

My table structure is
VALIDFROM VALIDTO
2008-01-23 00:00:00.000 2008-02-22 00:00:00.000
2008-02-22 00:00:00.000 2008-03-23 00:00:00.000
2008-03-23 00:00:00.000 2008-04-23 00:00:00.000
2008-06-23 00:00:00.000 2008-08-13 00:00:00.000
2008-08-13 00:00:00.000 2008-08-24 00:00:00.000
2008-08-24 00:00:00.000 2008-09-15 00:00:00.000
2008-10-1 00:00:00.000 2008-12-20 00:00:00.000

I need an incremental column by comparing validfrom and validto of previous row.

My output should be like this.

VALIDFROM VALIDTO Column1
2008-01-23 00:00:00.000 2008-02-22 00:00:00.000 1
2008-02-22 00:00:00.000 2008-03-23 00:00:00.000 1
2008-03-23 00:00:00.000 2008-04-23 00:00:00.000 1
2008-06-23 00:00:00.000 2008-08-13 00:00:00.000 2
2008-08-13 00:00:00.000 2008-08-24 00:00:00.000 2
2008-08-24 00:00:00.000 2008-09-15 00:00:00.000 2
2008-10-1 00:00:00.000 2008-12-20 00:00:00.000 3

Please help me to get this.

Thanks.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-01-05 : 05:16:48
Cross post http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=117168



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -