Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exclude Multiple Date Ranges From Result

Status
Not open for further replies.
Oct 2, 2007
41
US
I have a query that results in the following ID, StartDate and EndDate in a Table Variable(A). How do I now exclude data (in the next step) that was added to my production table(B) during any of these date ranges. The variable numbers of date ranges is based on the ID. Some may have no date rnages to be excluded others may have many.

ID StartDate EndDate
AE175AA08204 2006-03-31 2006-09-27
AE175AA08204 2008-10-21 2008-12-22
AE175AA08204 2008-12-26 2009-01-30

Thanks.

Woody
 
Something like this should work
Code:
SELECT a.*
FROM YourTransactionTable a
LEFT OUTER JOIN @YourTableVariable b
ON a.ID = b.ID AND a.TransactionDate BETWEEN b.StartDate AND b.EndDate
WHERE b.ID IS NULL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top