SET TERM ^ ;
ALTER PROCEDURE ISTAT_TAV_A_NAZIONI (
    DATA_GIORNO Timestamp,
    DALLA_DATA Timestamp,
    ALLA_DATA Timestamp )
RETURNS (
    AREA Varchar(24),
    CODICE Smallint,
    PRESENZE Integer,
    ARRIVI Integer,
    PARTENZA Integer )
AS
begin
  for select area,codice from wghgeo where area>'' and codice in (select WGHNAZ.NA_AREA from WGHNAZ,wghsps,WGHREG
    where wghsps.nazion=wghnaz.na_cod and wghreg.id_schedina=wghsps.codice
        and (wghreg.arrivo<=:ALLA_DATA and wghreg.PARTENZA>=:DALLA_DATA)) order by codice
    into :area,:codice
    do
    begin
    select count(wghnaz.na_cod) from wghsps,wghreg,wghnaz
        where wghnaz.na_area=:codice and wghsps.nazion=wghnaz.na_cod
        and wghreg.id_schedina=wghsps.codice
        and wghreg.arrivo<=:data_giorno
        and wghreg.partenza>:data_giorno into :presenze;
    select count(wghnaz.na_cod) from wghsps,wghreg,wghnaz
        where wghnaz.na_area=:codice
        and wghsps.nazion=wghnaz.na_cod
        and wghreg.id_schedina=wghsps.codice
        and wghreg.arrivo=:data_giorno into :arrivi;
    select count(wghnaz.na_cod) from wghsps,wghreg,wghnaz
        where wghnaz.na_area=:codice
        and wghsps.nazion=wghnaz.na_cod
        and wghreg.id_schedina=wghsps.codice
        and wghreg.partenza=:data_giorno into :partenza;
    suspend;
    end

end^
SET TERM ; ^

SET TERM ^ ;
ALTER PROCEDURE ISTAT_TAV_A_REGIONI (
    DATA_GIORNO Timestamp,DALLA_DATA timestamp,ALLA_DATA timestamp )
RETURNS (
    REGIONE Char(48),
    CODICE Integer,
    PRESENZE Integer,
    ARRIVI Integer,
    PARTENZA Integer )
AS
begin
  for select regioni.regione,regioni.codice from regioni where codice in (select provincie.REG from
        wghsps,wghreg,wghnaz,provincie where
            wghsps.nazion=wghnaz.na_cod
            and wghreg.id_schedina=wghsps.codice and provincie.prov=wghsps.provincia
            and wghnaz.na_cod=90
            and wghreg.arrivo<=:ALLA_DATA
            and wghreg.partenza>=:DALLA_DATA)
    into :regione,:codice
    do
    begin
    select count(provincie.reg) from wghsps,wghreg,wghnaz,provincie
        where provincie.reg=:codice and wghsps.nazion=wghnaz.na_cod
        and wghreg.id_schedina=wghsps.codice and provincie.prov=wghsps.provincia
        and wghnaz.na_cod=90
        and wghreg.arrivo<=:data_giorno
        and wghreg.partenza>:data_giorno into :presenze;
    select count(provincie.reg) from wghsps,wghreg,wghnaz,provincie
        where provincie.reg=:codice and wghsps.nazion=wghnaz.na_cod
        and wghreg.id_schedina=wghsps.codice and provincie.prov=wghsps.provincia
        and wghnaz.na_cod=90
        and wghreg.arrivo=:data_giorno into :arrivi;
    select count(provincie.reg) from wghsps,wghreg,wghnaz,provincie
        where provincie.reg=:codice and wghsps.nazion=wghnaz.na_cod
        and wghreg.id_schedina=wghsps.codice and provincie.prov=wghsps.provincia
        and wghnaz.na_cod=90
        and wghreg.partenza=:data_giorno into :partenza;
    suspend;
    end
end^
SET TERM ; ^

