Subject Re: Stored Procedure in Views
Author Svein Erling
--- In firebird-support@yahoogroups.com, "unordained" wrote:
> Without abandoning your idea of an updateable view, we can hack at
> the problem by making your view not need a stored procedure -- or
> at the very least, make it smarter.

I think we can abandon it:

create view MyWeekOrders (<Names of your fields>)
with FirstDateOfWeek (Sunday) as
(select distinct Delivery_Date-extract(weekday from Delivery_Date) from orders),
week(Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday) as
(select Sunday, Sunday+1, Sunday+2, Sunday+3, Sunday+4, Sunday+5, Sunday+6 from FirstDateOfWeek)
select <Here you put the fields you want in your view> from week w
left join Orders Mon on w.Monday = Mon.Delivery_Date
left join Orders Tue on w.Tuesday = Tue.Delivery_Date
left join Orders Wed on w.Wednesday = Wed.Delivery_Date
left join Orders Thu on w.Thursday = Thu.Delivery_Date
left join Orders Fri on w.Friday = Fri.Delivery_Date
left join Orders Sat on w.Saturday = Sat.Delivery_Date
left join Orders Sun on w.Sunday = Sun.Delivery_Date

If there are lots of orders, I think we ideally should have a WHERE clause in the first WITH part of the view to limit the number of records that have to be processed.

HTH,
Set