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 8396649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:35:29+00:00 2026-06-09T20:35:29+00:00

I have a table dbo.Trans which contains an id called bd_id (varchar) and transfer_date

  • 0

I have a table dbo.Trans which contains an id called bd_id(varchar) and transfer_date(Datetime), also an identifier member_id pk is trns_id and is sequential

Duplicates of bd_id and member_id exist in the table.

transfer_date       |bd_id| member_id | trns_id
2008-01-01 00:00:00 | 432 | 111       | 1  
2008-01-03 00:00:00 | 123 | 111       | 2  
2008-01-08 00:00:00 | 128 | 111       | 3  
2008-02-04 00:00:00 | 123 | 432       | 4
.......

For each member_id, I want to get the amount of days between dates and for each bd_id

E.G., member 111 used 432 from 2008-01-01 until 2008-02-01 so return should be 2
Then next would be 5

I know the DATEDIFF() function exists but I am not sure how to get the difference when dates are in the same table.

Any help appreciated.

  • 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-09T20:35:31+00:00Added an answer on June 9, 2026 at 8:35 pm

    You could try something like this.

    select T1.member_id,
           datediff(day, T1.transfer_date, T3.transfer_date) as DD
    from YourTable as T1
      cross apply (select top 1 T2.transfer_date
                   from YourTable as T2
                   where T2.transfer_date > T1.transfer_date and
                         T2.member_id = T1.member_id
                   order by T2.transfer_date) as T3
    

    SE-Data

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

Sidebar

Related Questions

I have this table CREATE TABLE [dbo].[friend_blocked_list]( [subdomain] [varchar](50) NOT NULL, [un] [nvarchar](50) NOT
I have a history table like below CREATE TABLE [dbo].[t_PettyCash_History] ( [TableName] [varchar] (500)
I have a table dbo.counters with columns idx, idx_device, DateTime, Data1, Data2 etc. idx
I have a table contains bus and student sign up information: CREATE TABLE [dbo].[BusSignupInstance](
I have a table called Bowzer which has a column called Type . When
I have a table called ApprovalTasks... Approvals has a status column I also have
I have a table like: CREATE TABLE [dbo].[MOVIES_HISTORY]( [DATE] [datetime] NOT NULL, [COUNT] [int]
I have table: CREATE TABLE [dbo].[test] ( [name] nvarchar(max) NULL, [date] datetime NULL )
I have a table with a nullable DateTime field: CREATE TABLE [dbo].[myTable]( [ID] [int]
I have a Table dbo.MSreplication_options using connectionString, i am trying to map this table

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.