Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 312229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:59:49+00:00 2026-05-12T07:59:49+00:00

The root problem: I have an application which has been running for several months

  • 0

The root problem: I have an application which has been running for several months now. Users have been reporting that it’s been slowing down over time (so in May it was quicker than it is now). I need to get some evidence to support or refute this claim. I’m not interested in precise numbers (so I don’t need to know that a login took 10 seconds), I’m interested in trends – that something which used to take x seconds now takes of the order of y seconds.

The data I have is an audit table which stores a single row each time the user carries out any activity – it includes a primary key, the user id, a date time stamp and an activity code:

create table AuditData (
    AuditRecordID int identity(1,1) not null, 
    DateTimeStamp datetime not null,
    DateOnly datetime null,
    UserID nvarchar(10) not null,
    ActivityCode int not null)

(Notes: DateOnly (datetime) is the DateTimeStamp with the time stripped off to make group by for daily analysis easier – it’s effectively duplicate data to make querying faster).

Also for the sake of ease you can assume that the ID is assigned in date time order, that is 1 will always be before 2 which will always be before 3 – if this isn’t true I can make it so).

ActivityCode is an integer identifying the activity which took place, for instance 1 might be user logged in, 2 might be user data returned, 3 might be search results returned and so on.

Sample data for those who like that sort of thing…:

1, 01/01/2009 12:39, 01/01/2009, P123, 1
2, 01/01/2009 12:40, 01/01/2009, P123, 2
3, 01/01/2009 12:47, 01/01/2009, P123, 3
4, 01/01/2009 13:01, 01/01/2009, P123, 3

User data is returned (Activity Code 2) immediate after login (Activity Code 1) so this can be used as a rough benchmark of how long the login takes (as I said, I’m interested in trends so as long as I’m measuring the same thing for May as July it doesn’t matter so much if this isn’t the whole login process – it takes in enough of it to give a rough idea).

(Note: User data can also be returned under other circumstances so it’s not a one to one mapping).

So what I’m looking to do is select the average time between login (say ActivityID 1) and the first instance after that for that user on that day of user data being returned (say ActivityID 2).

I can do this by going through the table with a cursor, getting each login instance and then for that doing a select to say get the minimum user data return following it for that user on that day but that’s obviously not optimal and is slow as hell.

My question is (finally) – is there a “proper” SQL way of doing this using self joins or similar without using cursors or some similar procedural approach? I can create views and whatever to my hearts content, it doesn’t have to be a single select.

I can hack something together but I’d like to make the analysis I’m doing a standard product function so would like it to be right.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:59:50+00:00Added an answer on May 12, 2026 at 7:59 am
    SELECT TheDay, AVG(TimeTaken) AvgTimeTaken
    FROM (  
    SELECT 
        CONVERT(DATE, logins.DateTimeStamp) TheDay
        , DATEDIFF(SS, logins.DateTimeStamp, 
                    (SELECT TOP 1 DateTimeStamp 
                     FROM AuditData userinfo 
                     WHERE UserID=logins.UserID 
                        and userinfo.ActivityCode=2 
                        and userinfo.DateTimeStamp > logins.DateTimeStamp )
                    )TimeTaken
    FROM AuditData logins
    WHERE 
        logins.ActivityCode = 1
    ) LogInTimes
    GROUP BY TheDay
    

    This might be dead slow in real world though.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 151k
  • Answers 151k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer In java, MyString.replace("\r\n","\n") replacing all \r\n with line feeds and… May 12, 2026 at 9:57 am
  • Editorial Team
    Editorial Team added an answer Keep it simple to start with - always the best… May 12, 2026 at 9:56 am
  • Editorial Team
    Editorial Team added an answer Use the parent() method: (".button-delete1").click(function() { alert($(this).parent().parent().attr("id")); }); May 12, 2026 at 9:56 am

Related Questions

I'm having a problem with an application hanging and giving me the default Please
Our application is a hybrid Win32 unmanaged application and a .NET 2.0 managed application.
Okay, so here's my problem: We use FOP for creating pretty report output. We
I was kind of scratching my head at this a week ago, and now
I am implementing a tree think of it as a folder structure so I

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.