Given this table:
How can I get the datediff in days between each status_date for each group of ID_Number? In other words I need to find the number of elapsed days for each status that the ID_Number has been given.
Some things to know:
- All ID_Number will have a received_date which should be the earliest date for each ID_Number (but app doesn't enforce)
- For each ID_Number there will be a status with a corresponding status_date which is the date that the ID_Number was given that particular status.
- The status column doesn't always necessarily go in the same order every time (app doesn't enforce)
- All ID_Number will have a closed_date which should be the latest date (but app doesn't enforce)
Sample output: So for ID_Number 2001, the first date (received_date) is 2009-05-02 and the next date you encounter has a status of 'open' and is 2009-05-02 so elapsed days is 0. Moving on to the next date encountered is 2009-05-10 with a status of 'invest' and the elapsed days is 8 counting from the prior date. The next date encountered is 2009-07-11 and the elapsed days is 62 counting from the previous date.
Edited to add:
Is it possible to have the elapsed days end up as a column on this table/view? I also forgot to add that this is SQL Server 2000.