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

  • Home
  • SEARCH
  • 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 9221027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:29:09+00:00 2026-06-18T03:29:09+00:00

I have multiple applications each with unique application ID’s, Each application has logs which

  • 0

I have multiple applications each with unique application ID’s, Each application has logs which are stored in a table. I want to know how to calculate the date difference
eg:

    AppID Start           Loggedon   change 
    A1    08/07/2010      08/09/2010 Xchange
    A1    08/07/2010      08/20/2010 Ychange
    A1    08/07/2010      08/30/2010 Zchange
    A2    07/07/2010      07/13/2010 Ychange
    A3    09/07/2010      09/09/2010 Xchange

So I want the values

Difference
2   (Difference between the application start date and 1st loggedon date)
11  (difference between 08/20 and 08/09, the prior row because AppID stayed the same)
10  (difference between 08/30 and 08/20, the prior row because AppID stayed the same)
6   (Difference between the application start date and 1st loggedon date)
2   (Difference between the application start date and 1st loggedon date)

Hope I am clear. How can I achieve this, I tried Ranking and Row_Number. But I might be wrong somewhere. I am using SQL Server and cannot use LAG()

  • 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-06-18T03:29:10+00:00Added an answer on June 18, 2026 at 3:29 am

    @Hogan has the correct approach, but for some reason, I can’t get it to work completely. Here is a slight variation that seems to produce the correct result — however, please accept @Hogan’s answer as he beat me to it 🙂

    WITH cte AS (
      SELECT AppId, Start, LoggedOn, 
      ROW_NUMBER() OVER (ORDER BY AppId) rn
    FROM Apps
      ) 
    SELECT c.AppId,
      CASE 
        WHEN c2.RN IS NULL
        THEN DATEDIFF(day,c.start,c.Loggedon)
        ELSE
             DATEDIFF(day,c2.Loggedon,c.Loggedon)
        END as TimeWanted
    FROM cte c
       LEFT JOIN cte c2 on c.AppId = c2.AppId
          AND c.rn = c2.rn + 1
    

    And here is the Fiddle.

    Good luck.

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

Sidebar

Related Questions

I have an application with multiple forms, each form has the same icon, so
I have multiple applications each having a GUI from a different technology. I need
I have a tab control in my WPF application with multiple tabs. Each tab
I have a web application with two servlets and multiple mappings associated with each
I have multiple web applications (PHP) which are being served to different customers from
In our web application, we have multiple small applications availables. Let us say A,B,C.
I have a system which contains multiple applications connected together using JMS and Spring
i have quite big ASP.NET MVC 2 application (multiple areas, each with own routing
I have a rather mundane Oracle table with seven rows. Each row has different
In my web application I have a simple employee form. Each employee has a

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.