Find time elapsed between two successive Status Changes

I am developing an SLA Report in which i have to find the elapse time between successive ‘status’ changes for each subrequet within a request.
See the example below:

RequestNum subReq_id Status TimeStamp Elapse Time


1000 S100 Just Create 25/02/2005 14:51:33 0Hrs 0Min 0Sec
1000 S100 Waiting for APproval 25/02/2005 14:51:35 0Hrs 0Min 0sec
1000 S100 Got Approval 26/02/2005 01:51:35 11Hrs 0Min 0Sec
1000 S100 Waiting in Queue 26/02/2005 01:55:25 0Hrs 3Min 50Sec
.
.
.
1000 S101 Just Created 25/02/2005 14:51:35 0Hrs 0Min 0Sec
1000 S101 Waiting for APproval 25/02/2005 14:51:36 0Hrs 0Min 1Sec
1000 S101 Got Approval 26/02/2005 15:50:36 0Hrs 59Min 0Sec
1000 S101 Waiting in Queue 26/02/2005 22:10:37 6Hrs 10Min 7Sec
.
.
.

1000 S102 . . .
. . .

In the above example, i need to calculate the ‘Elapse Time’ which is the difference between the two successive Timestamps when a ‘Status’ change occurs i.e the time taken for a subrequest to change from one Status to another.

Area of interest here is ‘How to catch the values of two successive timestamps, so that one can be subtracted from the other’

Thanks in advance :smiley:


PraMad (BOB member since 2005-03-08)

Please do a search before creating new topics, as this has been discussed very recently (and in multiple topics).

You need to be able to implement some sort of LAG or LEAD calculation on your database.


digpen :us: (BOB member since 2002-08-15)

Thanks for the reply.
I thorougly searched and found a topic that is similar to my need.
I will comeback if i get any other issues.

cheers :smiley:


PraMad (BOB member since 2005-03-08)

Can you please let me know how you solved it. I mean I did check the topics but wasnt successful.


buddiga (BOB member since 2005-03-04)

Hi,

I used Previous() function in finding the difference between two succssive values in a column.

Find the calculation that i used, below,

=If (<Status(NewUser)>=“Just Created”) Then 0 Else ((((ToNumber(SubStr(FormatDate(<Min TimeStamp within Status(NewUser)> ,“HH:mm:ss”) , 1 ,2))-ToNumber(SubStr(FormatDate(Previous(<Min TimeStamp within Status(NewUser)>) ,“HH:mm:ss”) , 1 ,2)))
*60)+(ToNumber(SubStr(FormatDate(<Min TimeStamp within Status(NewUser)> ,“HH:mm:ss”) , 4 ,2))-ToNumber(SubStr(FormatDate(Previous(<Min TimeStamp within Status(NewUser)>) ,“HH:mm:ss”) , 4 ,2))))*60)+(ToNumber(SubStr(FormatDate(<Min TimeStamp within Status(NewUser)> ,“HH:mm:ss”) , 7 ,2))-ToNumber(SubStr(FormatDate(Previous(<Min TimeStamp within Status(NewUser)>) ,“HH:mm:ss”) , 7 ,2)))

This is to find the difference between two successive dates with timestamps, in a column.
‘Break’ is applied on ‘Request number’ and ‘subrequest id’ .

Note: But this didnot solve my requirement fully. I am facing a strange problem with the Previous() function. When i use this function for the first time on a column then the values are coming fine, but if i do any sorting on that column or change the sequence the values are not shown proplerly i.e the difference between the column value and its previous value is not showing correctly. I am not able to get what the problem is.
Has anyone come accross this, please guide me :slight_smile:


PraMad (BOB member since 2005-03-08)

Instead of using previous() at reporter level use Lag function to create universe object and then use this in the query panel. Syntax for lag function.
m,n lag(m,1) order by(n) …depends on your logic you can also use “partition” before order by clause (partition acts as group by in lag function) if columns are from different tables. Hope this helps


buddiga (BOB member since 2005-03-04)

Hi,
We are using MS SQL Server2000 for database.I didn’t use LAG function earlier and know nothing about it.I could not find the LAG function under the list of functions available in Designer while creating an object.
So could you please guide me about the parameters of that function and how to use that.

Thanks in Advance :slight_smile:


PraMad (BOB member since 2005-03-08)

LAG function is an analytic function and it gives value from the previous row. You dont have it in designer since its an analytic function. I used this with oracle(8i) backend. I am not quite sure how it works with SQl server. But in time difference reports we usually use this LAG function.


buddiga (BOB member since 2005-03-04)