-- Aggiornamento campi date Campo, sta roba va fatta perchè abbiamo già dei clienti in produzione!

-- FPERR00K
ALTER TABLE FPERR00K DROP CONSTRAINT FPERR00Q;
ALTER TABLE FPERR00K ALTER COLUMN PXUHRI DATETIME;
ALTER TABLE FPERR00K ADD CONSTRAINT FPERR00K_TLLNNAPRV1 DEFAULT '19700101 00:00:00' FOR PXUHRI;
UPDATE FPERR00K SET PXUHRI = '19700101 00:00:00' WHERE PXUHRI IS NULL;
ALTER TABLE FPERR00K ALTER COLUMN PXUHRI DATETIME NOT NULL;
ALTER TABLE FPERR00K ADD CONSTRAINT FPERR00Q PRIMARY KEY(PXPRGI, PXHFAT, PXBFAT, PXUHRI, PXNFIL, PXNLIN, PXNERR);

-- FPPRO00F
ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATAPROT DATETIME;
ALTER TABLE FPPRO00F ADD CONSTRAINT FPPRO00F_TLLNNAPRV1 DEFAULT '19700101 00:00:00' FOR PZ_DATAPROT;
UPDATE FPPRO00F SET PZ_DATAPROT = '19700101 00:00:00' WHERE PZ_DATAPROT IS NULL;
ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATAPROT DATETIME NOT NULL;

ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATAACCET DATETIME;
ALTER TABLE FPPRO00F ADD CONSTRAINT FPPRO00F_TLLNNAPRV2 DEFAULT '19700101 00:00:00' FOR PZ_DATAACCET;
UPDATE FPPRO00F SET PZ_DATAACCET = '19700101 00:00:00' WHERE PZ_DATAACCET IS NULL;
ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATAACCET DATETIME NOT NULL;

ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATACONT DATETIME;
ALTER TABLE FPPRO00F ADD CONSTRAINT FPPRO00F_TLLNNAPRV3 DEFAULT '19700101 00:00:00' FOR PZ_DATACONT;
UPDATE FPPRO00F SET PZ_DATACONT = '19700101 00:00:00' WHERE PZ_DATACONT IS NULL;
ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATACONT DATETIME NOT NULL;

ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATAARCH DATETIME;
ALTER TABLE FPPRO00F ADD CONSTRAINT FPPRO00F_TLLNNAPRV4 DEFAULT '19700101 00:00:00' FOR PZ_DATAARCH;
UPDATE FPPRO00F SET PZ_DATAARCH = '19700101 00:00:00' WHERE PZ_DATAARCH IS NULL;
ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATAARCH DATETIME NOT NULL;

ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATAORARIC DATETIME;
ALTER TABLE FPPRO00F ADD CONSTRAINT FPPRO00F_TLLNNAPRV5 DEFAULT '19700101 00:00:00' FOR PZ_DATAORARIC;
UPDATE FPPRO00F SET PZ_DATAORARIC = '19700101 00:00:00' WHERE PZ_DATAORARIC IS NULL;
ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATAORARIC DATETIME NOT NULL;

ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATASTATO DATETIME;
ALTER TABLE FPPRO00F ADD CONSTRAINT FPPRO00F_TLLNNAPRV6 DEFAULT '19700101 00:00:00' FOR PZ_DATASTATO;
UPDATE FPPRO00F SET PZ_DATASTATO = '19700101 00:00:00' WHERE PZ_DATASTATO IS NULL;
ALTER TABLE FPPRO00F ALTER COLUMN PZ_DATASTATO DATETIME NOT NULL;

-- PAA0100F
ALTER TABLE PAA0100F DROP CONSTRAINT PAA0100Q;
DROP INDEX  PAA0101I ON PAA0100F;
ALTER TABLE PAA0100F ALTER COLUMN P1_DATAORARIC DATETIME;
ALTER TABLE PAA0100F ADD CONSTRAINT PAA0100F_TLLNNAPRV1 DEFAULT '19700101 00:00:00' FOR P1_DATAORARIC;
UPDATE PAA0100F SET P1_DATAORARIC = '19700101 00:00:00' WHERE P1_DATAORARIC IS NULL;
ALTER TABLE PAA0100F ALTER COLUMN P1_DATAORARIC DATETIME NOT NULL;

ALTER TABLE PAA0100F ALTER COLUMN P1_DATASTATO DATETIME;
ALTER TABLE PAA0100F ADD CONSTRAINT PAA0100F_TLLNNAPRV2 DEFAULT '19700101 00:00:00' FOR P1_DATASTATO;
UPDATE PAA0100F SET P1_DATASTATO = '19700101 00:00:00' WHERE P1_DATASTATO IS NULL;
ALTER TABLE PAA0100F ALTER COLUMN P1_DATASTATO DATETIME NOT NULL;

ALTER TABLE PAA0100F ADD CONSTRAINT PAA0100Q PRIMARY KEY(P1_KEYPRGINVIO, P1_KEYHEADERFATT, P1_KEYBODYFATT, P1_DATAORARIC);
CREATE INDEX PAA0101I ON PAA0100F (P1_KEYPRGINVIO ASC, P1_KEYHEADERFATT ASC, P1_KEYBODYFATT ASC, P1_DATAORARIC ASC);

-- PAA2800F
ALTER TABLE PAA2800F ALTER COLUMN PR_DATAORARIT DATETIME;
ALTER TABLE PAA2800F ADD CONSTRAINT PAA2800F_TLLNNAPRV1 DEFAULT '19700101 00:00:00' FOR PR_DATAORARIT;
UPDATE PAA2800F SET PR_DATAORARIT = '19700101 00:00:00' WHERE PR_DATAORARIT IS NULL;
ALTER TABLE PAA2800F ALTER COLUMN PR_DATAORARIT DATETIME NOT NULL;

ALTER TABLE PAA2800F ALTER COLUMN PR_DATAORACON DATETIME;
ALTER TABLE PAA2800F ADD CONSTRAINT PAA2800F_TLLNNAPRV2 DEFAULT '19700101 00:00:00' FOR PR_DATAORACON;
UPDATE PAA2800F SET PR_DATAORACON = '19700101 00:00:00' WHERE PR_DATAORACON IS NULL;
ALTER TABLE PAA2800F ALTER COLUMN PR_DATAORACON DATETIME NOT NULL;

-- PAF2800F
ALTER TABLE PAF2800F ALTER COLUMN PR_DATAORARIT DATETIME;
ALTER TABLE PAF2800F ADD CONSTRAINT PAF2800F_TLLNNAPRV1 DEFAULT '19700101 00:00:00' FOR PR_DATAORARIT;
UPDATE PAF2800F SET PR_DATAORARIT = '19700101 00:00:00' WHERE PR_DATAORARIT IS NULL;
ALTER TABLE PAF2800F ALTER COLUMN PR_DATAORARIT DATETIME NOT NULL;

ALTER TABLE PAF2800F ALTER COLUMN PR_DATAORACON DATETIME;
ALTER TABLE PAF2800F ADD CONSTRAINT PAF2800F_TLLNNAPRV2 DEFAULT '19700101 00:00:00' FOR PR_DATAORACON;
UPDATE PAF2800F SET PR_DATAORACON = '19700101 00:00:00' WHERE PR_DATAORACON IS NULL;
ALTER TABLE PAF2800F ALTER COLUMN PR_DATAORACON DATETIME NOT NULL;

-- PAFW300F
ALTER TABLE PAFW300F ALTER COLUMN PW_UPAG DATETIME;
ALTER TABLE PAFW300F ADD CONSTRAINT PAFW300F_TLLNNAPRV1 DEFAULT '19700101 00:00:00' FOR PW_UPAG;
UPDATE PAFW300F SET PW_UPAG = '19700101 00:00:00' WHERE PW_UPAG IS NULL;
ALTER TABLE PAFW300F ALTER COLUMN PW_UPAG DATETIME NOT NULL;

-- TLLNNAPRV -> Tolla non approva