I have a table with a start date and repeat counts (simplified):
CREATE TABLE tblSchedule (
schedStart timestamp,
schedRepeatMonth tinyint,
schedRepeatDays tinyint,
schedOpen bit
);
So, in a simplifed example, "open every Tuesday" would have a start date on a Tuesday and repeat every 7 days. The third Friday would start on a Friday and repeat once a month and 21 days. Closed on Christmas would have a date of Dec. 25th, no repeats, closed.
There are two types of queries it has to handle - "are we open on this date" and "how many times are we open between these dates". If the table were populated without repeats, these would be totally mundane queries and what I would like to do is create a select that produces rows as if they had been entered long-hand without repeats ie:
SELECT * from (
SELECT schedStart, schedEnd from tblSchedule
where schedStart between ('2001-01-01', '2001-12-31')
and *expand_ranges_into_non_repeating_rows_here*)
)
The trouble is that SQL is about filtering information out, not expanding it so creating several rows from a single one is not exactly normal. I could use a while loop to create a temporary table but this is the schedule for multiple items across the entire system so it's going to be commonly run a lot, albeit with some date ranges being more common than others.
Any ideas? Bonus if we can keep the solution as standard-sql as possible.
Edit: I suppose the question could be further simplified and abstracted to "How can I create a sequence of rows without using a table."