I have got a bit of 'brain fade' going on this afternoon, so if anyone can help with this mssql query it would be fantastic.
I have a table called 'seasons' with three columns (there are more but not relevant to the example): seasonId, date, tariffId
SeasonId is a unique key. A date can only have one tariffid, but a tariffId can have many different dates.
For example:
seasonId, date, tariffId
1 1 jan 2009 1
2 2 jan 2009 1
3 3 jan 2009 2
4 4 jan 2009 3
5 5 jan 2009 3
I'd like to have a query return the sequence/range of dates against a particular tariffId
Eg using the data above, it would return the following:
FromDate, ToDate, TariffId
1 Jan 2009 2 Jan 2009 1
3 Jan 2009 3 Jan 2009 2
4 Jan 2009 5 Jan 2009 3
Is this possible?
EDIT Thanks for all the answers so far! I am always amazed how far you get a response!
However, my example data probably wasn't complex enough as a tariff can have 1 or more date ranges
seasonId, date, tariffId
1 1 jan 2009 1
2 2 jan 2009 1
3 3 jan 2009 2
4 4 jan 2009 3
5 5 jan 2009 3
6 6 jan 2009 1
7 7 jan 2009 1
8 8 jan 2009 3
Would give:
FromDate, ToDate, TariffId
1 Jan 2009 2 Jan 2009 1
3 Jan 2009 3 Jan 2009 2
4 Jan 2009 5 Jan 2009 3
6 Jan 2009 7 Jan 2009 1
8 Jan 2009 8 Jan 2009 3
Ideas?
Thanks everyone for their help on this! This site is AWESOME!