--można uruchomić w programie isql przy pomocy polecenia:
--input nazwapliku.sql;

SET TERM ^;
CREATE PROCEDURE MOJAPROCEDURA 
(
  DATA_OD DATE,
  DATA_DO DATE
)
RETURNS
(
  OKRES_DATA_OD DATE,
  OKRES_DATA_DO DATE
)
AS
BEGIN
FOR
SELECT DISTINCT
Data+(mod(abs(EXTRACT(WEEKDAY FROM Data)-7),7)-2), 
Data+(mod(abs(EXTRACT(WEEKDAY FROM Data)-7),7)-2)+2 
FROM MojaTabela WHERE Data BETWEEN :DATA_OD AND :DATA_DO
AND EXTRACT(WEEKDAY FROM Data) IN (0,5,6)
INTO :OKRES_DATA_OD, :OKRES_DATA_DO 
DO SUSPEND ;
END^
COMMIT WORK^
SET TERM ;^