Subject Re: [ib-support] Help - Sum(TimeType)
Author Markus Ostenried
At 01:55 Friday, 26.07.2002 +0200, you wrote:
>At 20:22 Thursday, 25.07.2002 -0300, you wrote:
> >The Employee work every day in different times, and he can start and stop to
> >job any time. for example:
> >
> >In the date 01-Jul-2002 he started at 08:00 am and stop at 11:30 am, so he
> >worked 03:30.
> >In the date 02-Jul-2002 he started at 08:30 am and stop at 11:45 am, so he
> >worked 03:15.
> >In the date 03-Jul-2002 he started at 08:15 am and stop at 12:00 pm, so he
> >worked 03:45.
> >
> >I want to pay for him job
> >
> > Total hours worked: 10:30
> > Price by hour: $ 50,00
> > Amount: $ 525,00
>
> > EmplyeeID Char(3)
> > DateWorked Date
> > HoursWorked Time
>
>You can create a VIEW that does
>
>SELECT EXTRACT(HOUR FROM HoursWorked) + CAST(EXTRACT(MINUTE FROM
>HoursWorked) AS FLOAT) / 60
> >FROM EmployeeTimeWork
>
>"Cast as Float" is needed because otherwise Firebird does a Integer
>division instead of floating point.
>
>Then do a SELECT SUM() on the VIEW.

Well, I just found a better solution. Add one COMPUTED field to your table
like this:
ALTER TABLE EmployeeTimeWork
ADD RealHours COMPUTED BY (EXTRACT(HOUR FROM HoursWorked) +
CAST(EXTRACT(MINUTE FROM HoursWorked) AS FLOAT) / 60);

Then you can do directly
SELECT SUM(RealHours) FROM EmployeeTimeWork

The additional computed field won't slow your other selects down since the
value for the field is only computed when the field is included in your SELECT
statement.

HTH,
Markus