Вот код процедуры
CREATE PROCEDURE SSH_REPORT (
tuid integer,
date_b date,
date_e date)
returns (
tdate date,
name varchar(100),
timesr time)
as
declare variable max_time time;
declare variable min_time time;
begin
max_time='00:00:00';
min_time='00:00:00';
for select r.dates from workers w
left join registry r on r.id_worker=w.id
where r.dates>=:date_b and r.dates
into:tdate
do
begin
select max(r.times) from registry r
where r.dates=:tdate and r.id_worker=:tuid
into:max_time;
select min(r.times) from registry r
where r.dates=:tdate and r.id_worker=:tuid
into:min_time;
if (:max_time<>:min_time) then timesr=:max_time-:min_time;
if (:max_time=:min_time) then timesr=:max_time;
end
suspend;
end