troubleshooting Question

SQL Query to find record above and below a specified date

Avatar of dwknight
dwknight asked on
Web BrowsersMicrosoft SQL Server 2005Microsoft SQL Server 2008
9 Comments1 Solution683 ViewsLast Modified:
I have a record set that has the following record structure:

RecordID
BeginDate
EndDate
Details

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.

ie
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.
ASKER CERTIFIED SOLUTION
pmcgivern

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 9 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros