SQL Help Needed

Soldato
Joined
11 Feb 2004
Posts
4,532
Location
Surrey, UK
I have a table with the following data.

Ticket, Sequence, OldValue. NewValue, Date

1, 1, 'New', 'Closed', 07/01/2009 10:27:01
2, 2, 'New', 'In Progress', 10/01/2009 10:27:01
2, 3, 'In Progress', 'Assigned', 10/01/2009 11:45:45
2, 4, 'Assigned', 'Closed', 10/01/2009 13:32:56
3, 5, 'New', 'Assigned', 11/01/2009 08:22:23
4, 6, 'New', 'Assigned', 11/01/2009 15:44:24
4, 7, 'Assigned', 'In Progress', 12/01/2009 09:34:29
4, 8, 'In Progress', 'Resolved', 12/01/2009 13:59:49
4, 9, 'Resolved', 'Closed', 12/01/2009 14:01:22


I need to extract each record where the last entry for NewValue is 'Closed'.
Using the example above it would be tickets 1 (sequence#1), 2 (sequence#4) and 4 (sequence#9) - not 3 where the last entry is 'Assigned'.

I've tried a subquery using max which simply returns the very last record added, rather than all records where the criteria is met.

Help would be appreciated!
 
Last edited:
All I really need is the ticket number which can then be linked to other tables.
Unfortunatley the tickets can be reopened.
 
Thanks guys, especially to aftershxck for your code which works. The sequence number is incremental so checking against it is fine.
I agree with all in terms of the table design but that's down to the CRM vendor not me!
Thanks again.
Dom
 
Back
Top Bottom