December 29, 2011 at 3:56 am
I have the following fields in my table.
UserName DateTime Action
abc 22/1/2011 23:45 xyz
abc 23/1/2011 10:00 pqr
abc 23/1/2011 15:00 pqr
abc 23/1/2011 20:00 pqr
abc 23/1/2011 21:00 pqr
abc 23/1/2011 55:00 pqr
If the user has not done any action in 30 min,I can say his session is ended.So i need to take be before that record and calculate timespan
December 29, 2011 at 4:29 am
Is this is a homework question? What have you tried so far? It really isn't clear what you require, in any case. Please also provide DDL in the form of a CREATE TABLE statement, sample data in the form of INSERT statements, and required results.
John
December 30, 2011 at 5:32 am
Based on the data supplied I think the answer is as follows:
declare @fdatetime datetime, @pdatetime datetime
Select top 1 @ldatetime=datetime from <yourtablename> where username = <usernameyouare checking> order by datetime desc
Select top 1 @pdatetime=datetime from <yourtablename> where username = <usernameyouare checking> and datetime < @ldatetime order by datetime desc
If datediff(mi,@pdatetime,@ldatetime)> 30
Begin
<sessionendedlogic>
End
I am assuming you would put this in a stored procedure and either send in a username or run it without parameters and loop through a user table for all users checking every 30 minutes or something of that nature. Sorry I can't be more specific but the question was not real specific.
HTH,
DG
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply