I have a table called OffDays, where weekends and holiday dates are kept. I have a table called LeadTime where amount of time (in days) for a product to be manufactured is stored. Finally I have a table called Order where a product and the order date is kept.
Is it possible to query when a product will be finished manufacturing without using stored procedures or loops?
For example:
- OffDays has 2008-01-10, 2008-01-11, 2008-01-14.
- LeadTime has 5 for product 9.
- Order has 2008-01-09 for product 9.
The calculation I'm looking for is this:
- 2008-01-09 1
- 2008-01-10 x
- 2008-01-11 x
- 2008-01-12 2
- 2008-01-13 3
- 2008-01-14 x
- 2008-01-15 4
- 2008-01-16 5
I'm wondering if it's possible to have a query return 2008-01-16 without having to use a stored procedure, or calculate it in my application code.
Edit (why no stored procs / loops): The reason I can't use stored procedures is that they are not supported by the database. I can only add extra tables / data. The application is a third party reporting tool where I can only control the SQL query.
Edit (how i'm doing it now): My current method is that I have an extra column in the order table to hold the calculated date, then a scheduled task / cron job runs the calculation on all the orders every hour. This is less than ideal for several reasons.