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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:37:37+00:00 2026-05-10T15:37:37+00:00

I’m trying to write a query that will pull back the two most recent

  • 0

I’m trying to write a query that will pull back the two most recent rows from the Bill table where the Estimated flag is true. The catch is that these need to be consecutive bills.

To put it shortly, I need to enter a row in another table if a Bill has been estimated for the last two bill cycles.

I’d like to do this without a cursor, if possible, since I am working with a sizable amount of data and this has to run fairly often.

Edit

There is an AUTOINCREMENT(1,1) column on the table. Without giving away too much of the table structure, the table is essentially of the structure:

 CREATE TABLE Bills (   BillId INT AUTOINCREMENT(1,1,) PRIMARY KEY,   Estimated BIT NOT NULL,   InvoiceDate DATETIME NOT NULL ) 

So you might have a set of results like:

 BillId               AccountId            Estimated InvoiceDate -------------------- -------------------- --------- ----------------------- 1111196              1234567              1         2008-09-03 00:00:00.000 1111195              1234567              0         2008-08-06 00:00:00.000 1111194              1234567              0         2008-07-03 00:00:00.000 1111193              1234567              0         2008-06-04 00:00:00.000 1111192              1234567              1         2008-05-05 00:00:00.000 1111191              1234567              0         2008-04-04 00:00:00.000 1111190              1234567              1         2008-03-05 00:00:00.000 1111189              1234567              0         2008-02-05 00:00:00.000 1111188              1234567              1         2008-01-07 00:00:00.000 1111187              1234567              1         2007-12-04 00:00:00.000 1111186              1234567              0         2007-11-01 00:00:00.000 1111185              1234567              0         2007-10-01 00:00:00.000 1111184              1234567              1         2007-08-30 00:00:00.000 1111183              1234567              0         2007-08-01 00:00:00.000 1111182              1234567              1         2007-07-02 00:00:00.000 1111181              1234567              0         2007-06-01 00:00:00.000 1111180              1234567              1         2007-05-02 00:00:00.000 1111179              1234567              0         2007-03-30 00:00:00.000 1111178              1234567              1         2007-03-02 00:00:00.000 1111177              1234567              0         2007-02-01 00:00:00.000 1111176              1234567              1         2007-01-03 00:00:00.000 1111175              1234567              0         2006-11-29 00:00:00.000 

In this case, only records 1111188 and 1111187 would be consecutive.

  • 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-10T15:37:38+00:00Added an answer on May 10, 2026 at 3:37 pm

    Assuming the rows have sequential IDs, something like this may be what you’re looking for:

    select top 1 *  from  Bills b1 inner join Bills b2 on b1.id = b2.id - 1 where b1.IsEstimate = 1 and b2.IsEstimate = 1 order by b1.BillDate desc 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 171k
  • Answers 171k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You need to escape the backslashes too: "func\\((.*),(-?[0-9.]*),(-?[0-9.]*),(-?[0-9.]*)\\)" That string… May 12, 2026 at 2:16 pm
  • Editorial Team
    Editorial Team added an answer The original urllib simply does not raise an exception on… May 12, 2026 at 2:16 pm
  • Editorial Team
    Editorial Team added an answer Responses to your questions: If you use Ant maybe this… May 12, 2026 at 2:16 pm

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
In order to apply a triggered animation to all ToolTip s in my app,
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.