tags:

views:

249

answers:

3

Hi, I have a table of Prices with a start date, end date and price. I want a search to pass in a date range and return whether a price exists for all days in that range. The date range can span multiple prices, just not have any gaps in between.

Is this possible?

Prices
startDate datetime
endDate datetime
price

DECLARE @startDate datetime = '2010-04-01',
        @endDate datetime = '2010-04-30'

SELECT * FROM Prices WHERE @startDate BETWEEN startDate AND endDate...
+1  A: 

Add a grouping to your query with a having statement :

HAVING COUNT(*) = DATEDIFF(DAY,@StartDate,@EndDae)+1
Gary W
A: 

If you have an Auxilliary dates table you can use any of these Relational Division techniques http://www.simple-talk.com/sql/t-sql-programming/divided-we-stand-the-sql-of-relational-division/

Martin Smith
A: 

I used this in the end, works perfectly:

http://stackoverflow.com/questions/271595/getting-dates-between-a-range-of-dates

CL4NCY