I have a table in a MSSQL database that looks like this:
Timestamp (datetime)
Message (varchar(20))
Once a day, a particular process inserts the current time and the message 'Started' when it starts. When it is finished it inserts the current time and the message 'Finished'.
What is a good query or set of statements that, given a particular date, returns:
- 0 if the process never started
- 1 if the process started but did not finish
- 2 if the process started and finished
There are other messages in the table, but 'Started' and 'Finished' are unique to this one process.
EDIT: For bonus karma, raise an error if the data is invalid, for example there are two 'Started' messages, or there is a 'Finished' without a 'Started'.