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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:09:53+00:00 2026-05-28T08:09:53+00:00

I have a table of play data that I’m using for a prototype. I’m

  • 0

I have a table of play data that I’m using for a prototype. I’m generating the data while I’m at work, but when I leave and my machine goes to sleep, the data generation stops. This has cause large gaps in my collection of items.

I would like to be able to shift the values of each item in the DateTimeCreated collumn of my table so that there isn’t a gap of more than 10 minutes between any item and the next generated item.

The structure of the table is like this:

CREATE TABLE [dbo].[Items](
    [Id] [uniqueidentifier] NOT NULL,
    [DateTimeCreated] [datetimeoffset](7) NOT NULL,
    [AuthorId] [uniqueidentifier] NOT NULL,
    [Source] [varchar](max) NOT NULL,       
    [FullText] [varchar](max) NOT NULL,
 CONSTRAINT [PK_Items] PRIMARY KEY CLUSTERED 
(
    [Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

I was thinking about doing this in L2S, but I have over 1 million records, so IDK if that is the best solution (iterating over each item). I know there has to be some way to do this in SQL that will be much faster.

  • 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-28T08:09:54+00:00Added an answer on May 28, 2026 at 8:09 am

    An alternative Ranking-Functions Approach (not 100% tested):

    DECLARE @tenMinutes AS INT = 600;
    
    
    WITH StartingPoints AS
    (
        SELECT DateTimeCreated, ROW_NUMBER() OVER(ORDER BY DateTimeCreated) AS rownum
        FROM dbo.Items AS A
        WHERE NOT EXISTS(
            SELECT * FROM dbo.Items AS B
            WHERE B.DateTimeCreated < A.DateTimeCreated 
              AND DATEDIFF(SECOND,B.DateTimeCreated, A.DateTimeCreated) BETWEEN 0 AND @tenMinutes
        )
    ),
    EndingPoints AS
    (
        SELECT DateTimeCreated, ROW_NUMBER() OVER(ORDER BY DateTimeCreated) AS rownum
        FROM dbo.Items AS A
        WHERE NOT EXISTS(
            SELECT * FROM dbo.Items AS B
            WHERE A.DateTimeCreated < B.DateTimeCreated 
              AND DATEDIFF(SECOND,A.DateTimeCreated, B.DateTimeCreated) BETWEEN 0 AND @tenMinutes
        )
    ),
    Islands AS
    (
        SELECT S.DateTimeCreated AS start_range,
               E.DateTimeCreated AS end_range,
               ROW_NUMBER() OVER(ORDER BY S.DateTimeCreated) AS row_num
        FROM StartingPoints AS S
        JOIN EndingPoints AS E on E.rownum = S.rownum
    ),
    Ofs AS
    (
        SELECT I2.start_range, 
               I2.end_range,  
               I1.end_range AS prev,
               DATEDIFF(SECOND, I1.end_range, I2.start_range) AS offset 
        FROM Islands AS I1
        JOIN Islands AS I2 ON I2.row_num = I1.row_num + 1 OR I2.row_num IS NULL
    ),
    CmlOfs AS
    (
        SELECT O1.start_range,
               O1.end_range,
               O1.prev,
               O1.offset,
               (SELECT SUM(O2.offset) FROM Ofs AS O2
                WHERE O2.start_range <= O1.start_range) AS cum_offset
        FROM Ofs AS O1
    ),
    UpdateQ AS
    (
        SELECT Items.*, DATEADD(SECOND, -1 * CmlOfs.cum_offset, Items.DateTimeCreated) AS new_value
        FROM Items
        JOIN CmlOfs ON Items.DateTimeCreated BETWEEN CmlOfs.start_range AND CmlOfs.end_range
    )
    UPDATE UpdateQ
    SET DateTimeCreated = new_value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a <table> that the data is separated per 2 <tr> 's So
I have table rows of data in html being filled from a CGI application.
I have table with some fields that the value will be 1 0. This
I have table in data base name train delay, with columns train number(int), DelayTime(int),
I have 2 tables with the same schema, one is just a table that
I am trying to play around with C data structure (hash table). I am
I have a rather peculiar data source I have to work with (an interface
I have a table in my database that stores musicians in a table as
I have an SQLite DB with one table that holds IDs for several strings,
I have an Access 2003 database using MS-JET linked tables (that is, there are

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.