If there is an easier way to do this -- I am all ears...Right now, my one-track mind screams "CURSOR!"....
I have a table, sorted by SORT_ID:
SORT_ID ID START_DT END_DT PENDING COMPLETED
1 X 1/15/03 1/21/03
2 X 1/17/03 2/17/03
3 Y 1/05/03 1/11/03
4 Y 3/10/03 3/16/03
5 Y 4/1/03 4/31/03
6 Y 4/28/03 4/31/03
7 Y 5/1/03 5/7/03
I want to take that table and define where each record is chronologically -- for example -- sort_id=2 has ID=X, on 1/17/03 when this record ocurred -- how many pending/good records existed (assume if time expires it moves from pending to good) -- so when I see record 2 on 1/17/03, I know I have 1 Pending (sort_id=1 is not yet expired), 0 Completed records.
Example 2 -- when I hit sort_id=6, I want to know I have 1 pending record (sort_id=5 is still pending) and 2 completed (sort_id 3,4 are completed by 4/28 (the start_date of sort_id=6).
SORT_ID ID START_DT END_DT PENDING COMPLETED
1 X 1/15/03 1/21/03 0 0
2 X 1/17/03 2/17/03 1 0
3 Y 1/05/03 1/11/03 0 0
4 Y 3/10/03 3/16/03 0 1
5 Y 4/1/03 4/31/03 0 2
6 Y 4/28/03 4/31/03 1 2
7 Y 5/1/03 5/7/03 0 3
In order to do this -- I need to keep each date as I scroll down through the cursor -- so I can calculate at each record with the same ID.....
Unfortunately, my cursor skills in SQL Server are not too great - I can scroll through a dataset and compare records -- but can't find a good example of how to "keep" a variable list of dates for these calculations....
Ideas appreciated -- and, if you have a better way -- I am all ears...
Thanks.
I have a table, sorted by SORT_ID:
SORT_ID ID START_DT END_DT PENDING COMPLETED
1 X 1/15/03 1/21/03
2 X 1/17/03 2/17/03
3 Y 1/05/03 1/11/03
4 Y 3/10/03 3/16/03
5 Y 4/1/03 4/31/03
6 Y 4/28/03 4/31/03
7 Y 5/1/03 5/7/03
I want to take that table and define where each record is chronologically -- for example -- sort_id=2 has ID=X, on 1/17/03 when this record ocurred -- how many pending/good records existed (assume if time expires it moves from pending to good) -- so when I see record 2 on 1/17/03, I know I have 1 Pending (sort_id=1 is not yet expired), 0 Completed records.
Example 2 -- when I hit sort_id=6, I want to know I have 1 pending record (sort_id=5 is still pending) and 2 completed (sort_id 3,4 are completed by 4/28 (the start_date of sort_id=6).
SORT_ID ID START_DT END_DT PENDING COMPLETED
1 X 1/15/03 1/21/03 0 0
2 X 1/17/03 2/17/03 1 0
3 Y 1/05/03 1/11/03 0 0
4 Y 3/10/03 3/16/03 0 1
5 Y 4/1/03 4/31/03 0 2
6 Y 4/28/03 4/31/03 1 2
7 Y 5/1/03 5/7/03 0 3
In order to do this -- I need to keep each date as I scroll down through the cursor -- so I can calculate at each record with the same ID.....
Unfortunately, my cursor skills in SQL Server are not too great - I can scroll through a dataset and compare records -- but can't find a good example of how to "keep" a variable list of dates for these calculations....
Ideas appreciated -- and, if you have a better way -- I am all ears...
Thanks.