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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:38:08+00:00 2026-06-15T20:38:08+00:00

I am working this on MS SQL. Anyone knows how to derive the consecutive_d

  • 0

I am working this on MS SQL. Anyone knows how to derive the consecutive_d column? Consecutive days should be solely based on ENTER_DT regardless of times. And if an employee enters many times in the same day it is still counted as one consecutive days.

PASS_M|  ENTER_DT................|CONSECUTIVE_D
Boo K K    5/1/2012 11:55:00 PM       1  
Boo K K    5/2/2012 11:30:00 PM       2  
Boo K K    5/4/2012 10:30:00 AM       1  
LIAW S     4/30/2012 11:48:52 PM      1  
LIAW S     5/1/2012 00:11:07 AM       2  
LIAW S     5/1/2012 12:32:07 AM       2  
LIAW S     5/1/2012 4:42:02 AM        2    
LIAW S     5/2/2012 1:10:09 AM        3  
LIAW S     5/2/2012 1:43:06 AM        3   
LIAW S     5/4/2012 2:17:47 AM        1   

Update: this is what i have tried:

SELECT PASS_M, ENTRY_DT, DATEDIFF(D, MIN(ENTRY_DT) OVER (PARTITION BY PASS_M), ENTRY_DT) + 1 AS CONSECTUTIVE_DAYS
INTO         TEMP_TARGET
FROM         TEMP_5
ORDER BY PASS_M, ENTRY_DT;
  • 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-15T20:38:10+00:00Added an answer on June 15, 2026 at 8:38 pm

    Use

    SELECT *, CONVERT(DATE,GETDATE()) AS DateOnly, SUM(CONSECUTIVE_D) as CONSECUTIVE_SUM GROUP BY DateOnly;

    This allows you to group elements by Date by extracting it from the datetime and then the sum of CONSECUTIVE_D will be CONSECUTIVE_SUM

    I hope that’s what you were looking for 🙂

    You can build your own custom query from this one!
    Requested Update

    SELECT
    PASS_M, 
    ENTRY_DT, 
    (DATEDIFF(D, MIN(ENTRY_DT) OVER (PARTITION BY PASS_M), ENTRY_DT) + 1) AS CONSECTUTIVE_DAYS,
    CONVERT(DATE,ENTRY_DT) AS DateOnly,
    SUM(CONSECUTIVE_DAYS) as CONSECUTIVE_SUM
    
    INTO         TEMP_TARGET
    FROM         TEMP_5
    GROUP BY DateOnly
    ORDER BY PASS_M;
    

    In my head, that should do the trick! Don’t ORDER BY ENTRY_DT, you now want to GROUP BY DateOnly

    Here’s a link about how to Turn datetime into date 🙂

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

Sidebar

Related Questions

I'm not sure why this SQL query is not working. I'm new to SQL/PHP
Im working in an SQL Query like this: (sorted by the station visits) TRAIN_ID
I am trying to get this awesome JQuery plugin working with SQL Server. I
I'm working on a SQL Server 2008 database. This database has two tables. Book
I'm working with SQL, and I can't seem to figure this out for the
So I have this query working (where signal_data is a column) in Sybase but
I am tired of working this out myself , i cannot understand the way
i am new in programming under linux and trying to get working this code:
I'm a LAMP guy and ended up working this small news module for an
I do not get the last version of node-http-proxy working (this used to work

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.