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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:25:17+00:00 2026-05-10T17:25:17+00:00

I have a database issue that i currently cannot wrap my head around with

  • 0

I have a database issue that i currently cannot wrap my head around with an easy solution. In my db I have a table that stores event values.. 0’s and 1’s with a timestamp. Issue being that it is possible for there to be the same event to occur twice as a business rule. Like below

  • ‘2008-09-22 16:28:14.133’, 0
  • ‘2008-09-22 16:28:35.233’, 1
  • ‘2008-09-22 16:29:16.353’, 1
  • ‘2008-09-22 16:31:37.273’, 0
  • ‘2008-09-22 16:35:43.134’, 0
  • ‘2008-09-22 16:36:39.633’, 1
  • ‘2008-09-22 16:41:40.733’, 0

in real life these events are cycled and I’m trying to query over to get the cycles of these but I need to ignore the duplicate values ( 1,1 ) the current solution is using a SQL cursor to loop each and throw out the value if the previous was the same. I’ve considered using a trigger on the insert to clean up in a post processed table but I can’t think of an easy solution to do this set based.

Any ideas or suggestions?

Thanks

  • 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. 2026-05-10T17:25:18+00:00Added an answer on May 10, 2026 at 5:25 pm

    This uses a SQL Server Common Table Expression, but it can be inlined, with table t with columns dt and cyclestate:

    ;WITH Firsts AS (     SELECT t1.dt         ,MIN(t2.dt) AS Prevdt     FROM t AS t1     INNER JOIN t AS t2         ON t1.dt < t2.dt         AND t2.cyclestate <> t1.cyclestate     GROUP BY t1.dt ) SELECT MIN(t1.dt) AS dt_start     ,t2.dt AS dt_end FROM t AS t1 INNER JOIN Firsts     ON t1.dt = Firsts.dt INNER JOIN t AS t2     ON t2.dt = Firsts.Prevdt     AND t1.cyclestate <> t2.cyclestate GROUP BY t2.dt     ,t2.cyclestate HAVING MIN(t1.cyclestate) = 0 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that reads a table from a database. I issue an
I have database with many tables. In the first table, I have a field
I have a database that contains a date and we are using the MaskedEditExtender
I have a database table and one of the fields (not the primary key)
I have a database file that is generated on a PC using Sqlite. This
I currently have a listing of data that has a randomly generated order listing.
I have a script that appends some rows to a table. One of the
I have a distributed windows application (written in C#) that currently uses MSDE. The
I have designed database tables (normalised, on an MS SQL server) and created a
I have a database with names in it such as John Doe etc. Unfortunately

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.