I’ve got a table that contains a LocationId field. In some cases, where a record shares the same foreign key, the LocationId might come through as -1.
What I want to do is in my select query is in the case of this happening, the previous location.
Example data:
Record FK StartTime EndTime Location
1 110 2011/01/01 12.30 2011/01/01 6.10 456
2 110 2011/01/01 3.40 2011/01/01 4.00 -1
3 110 2011/01/02 1.00 2011/01/02 8.00 891
4 110 2011/01/02 5.00 2011/01/02 6.00 -1
5 110 2011/01/02 6.10 2011/01/02 6.30 -1
The -1 should come out as 456 for record 2, and 891 for record 4 and 5
For the entire result set