I couldn't find the reason to create the view everytime called the procedure,
except the Noted below.
The following way would be easier...
(1) create a little modified view once which is...
a) added a column MovPolizaFecha in column-list of the view(and select-list of body of the view).
b) removed conditions for MOVIMIENTOS.MovPolizaFecha from where clause.
(2) When using the view, add the conditions for MovPolizaFecha in the view, like...
Code:
SELECT ...
...
FROM COBRANZA.ViewMOVIMIENTOSCLIENTES VMC
...
WHERE
...
AND VMC.MovPolizaFecha
BETWEEN FechaIniMonitoreo
AND FechaFinMonitoreo
;
or
Code:
SELECT ...
...
FROM COBRANZA.ViewMOVIMIENTOSCLIENTES VMC
...
WHERE
...
AND VMC.MovPolizaFecha
BETWEEN '2011-09-01'
AND '2011-09-07'
;
Note:
If you want to make the range of MovPolizaFecha stable(i.e. guarateed the same) for a while,
an idea is making another table to store the range of MovPolizaFecha, like...
Code:
CREATE TABLE COBRANZA.MOVIMIENTOSCLIENTES_parm
( FechaIniMonitoreo DATE
, FechaFinMonitoreo DATE
);
INSERT INTO COBRANZA.MOVIMIENTOSCLIENTES_parm
VALUES ('0001-00-01' , '0001-01-01');
and join the table in the view, like...
Code:
CREATE view COBRANZA.ViewMOVIMIENTOSCLIENTES
(...) AS
SELECT
...
FROM
...
JOIN COBRANZA.MOVIMIENTOSCLIENTES_parm AS parm
ON MOVIMIENTOS.MovPolizaFecha
BETWEEN parm.FechaIniMonitoreo
AND parm.FechaFinMonitoreo
WHERE
...
After all, update the values in the parm table before using the view, like...
Code:
UPDATE COBRANZA.MOVIMIENTOSCLIENTES_parm
SET (FechaIniMonitoreo , FechaFinMonitoreo)
= ('2011-09-01' , '2011-09-07')
;