I'm not sure I understand what difficulty you are having...
If I understand your problem correctly, I'll assume the following:
1. Your products table contains two columns I'll call 'PStart' and 'PEnd' which are integer (not datetime) columns containing a year value (e.g. 2003) and which represent the years of availability for the part. I'll further assume that a table constraint exists on these two columns such that PStart<=PEnd.
2. The query has two parameters '@QStart' and '@QEnd' which are the requested date ranges. These are also integers in the same format as the product years. The client application has insured that these two dates obey the constraint that @QStart<=@QEnd.
If you analyze how the query year values relate to the product year values, there are 6 possible combinations, of which 4 are valid (2 represent the query ranges totally before or totally after the product availability range, so these products should not be selected.
I think the query should be something like:
Code:
SELECT ...
FROM Products
WHERE @QStart BETWEEN PStart AND PEnd
OR @QEnd BETWEEN PStart AND PEnd
OR PStart BETWEEN @QStart AND @QEnd
OR PEnd BETWEEN @QStart AND @QEnd
...
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com