I have the following table Foo:
start | end | cause
-------------+-------------+----------
2007/12/22 | 2008/02/12 | 2
2008/03/18 | 1900/01/01 | -1
there are stored various periods of time. cause '-1' and end '1900/01/01' means the time period has no end. Under certain conditions, the application using this table writes records into the table that look like the following:
start | end | cause
-------------+-------------+----------
2007/12/22 | 2008/02/12 | 2
2008/03/18 | 2008/05/16 | 9
2008/05/17 | 1900/01/01 | -1
A time period with cause '9' should be read over. Each each of those periods have another period starting the next day. Look at the 2nd and 3rd record of Foo, the time period ends with 2008/05/16 (cause '9'), and the next starts with 2008/05/17.
I want to create a view that looks like the following:
start | end | cause
-------------+-------------+----------
2007/12/22 | 2008/02/12 | 2
2008/03/18 | 1900/01/01 | -1
I hope it is clear what I am trying to do. I tried my best, but I don't get it. I hope somebody can help me.
I am using SQL Server 2005 Express and I know the whole table design is crap (since I would be best just to not write those 'cause 9' records), but it is a legacy design and I can't change it.