We help IT Professionals succeed at work.
Get Started

SQL Query to find record above and below a specified date

Last Modified: 2012-05-11
I have a record set that has the following record structure:


I have a situation where a specified date (ie 16/03/2011) needs to be evaluated against the current recordset. The specified date will pretty much always occur between the records in the recordset  (ie - between the end date of record 1 and the start date of record 2)

The recordset will be made up of a number of records that are ordered by date range. The start date and end dates for each record will never overlap another record.

Recordid       BeginDate       EndDate         Details
1                    04/01/2011     06/01/2011    Some Details
2                    10/01/2011    15/01/2011    Some Additional Detail
3                     20/01/2011    25/01/2011   Some Detail in Addition

I wanted a huge amount of help writing an SQL query that would be able to return the record before and after the specified date (16/01/2011). The date will be specified by user entry.

Thanks for the help in advance.
Watch Question
This problem has been solved!
Unlock 1 Answer and 9 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE