BEGIN
/*---------------------------------------------------------------------------*/
/* Do periody mesic a rok patri tehdy, pokud zacatek nebo konec mesice patri */
/* do dane periody. Pokud vyjde, ze mesic patri do vice obdobi vraci obdobi s */
/* ktere zacina pozdeji */
mFirstDay = 1;
/* Zjistime posledni den mesice */
select LastDayOfMonth from MonthLastDay(:AMonth, :AYear) into :mLastDay;
/* Vypocteme prvni a posledni den mesice ve formatu data */
mFirstDate = ib_encodedate(:AYear, :AMonth, :mFirstDay);
mLastDate = ib_encodedate(:AYear, :AMonth, :mLastDay);
/* Vybereme obdobi */
select ID from Periods
where ((:mFirstDate between DateFrom$Date and DateTo$Date) or
(:mLastDate between DateFrom$Date and DateTo$Date))
and
DateFrom$Date in
(select max(DateFrom$Date) from Periods
where
:mFirstDate between DateFrom$Date and DateTo$Date or
:mLastDate between DateFrom$Date and DateTo$Date
)
into :Period_ID;
suspend;
END;