IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMBD_ORGPROS' AND KSQL_COL_NAME ='FNAME') 
ALTER TABLE T_PMBD_ORGPROS ADD  (FNAME VARCHAR(50) DEFAULT ' ' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMBD_CALENDAR' AND KSQL_COL_NAME ='FNAME') 
ALTER TABLE T_PMBD_CALENDAR ADD (FNAME VARCHAR(50) DEFAULT ' ' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FNAME') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FNAME VARCHAR(50) DEFAULT ' ' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FREMARK') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FREMARK VARCHAR(255) DEFAULT ' ' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FDELIVERYSCHEME') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FDELIVERYSCHEME BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FLABELCOLOR') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FLABELCOLOR BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FISSPECIAL') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FISSPECIAL CHAR(1) DEFAULT '0' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FLICENSEGROUP') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FLICENSEGROUP  BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FDEVICES') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FDEVICES BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FWORKRANGE') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FWORKRANGE BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FWEIGHTVARIANT') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FWEIGHTVARIANT CHAR(1) DEFAULT '0' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FFLYHOURS') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FFLYHOURS DECIMAL(23,10) DEFAULT 0 NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FFLYREPEAT') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FFLYREPEAT DECIMAL(23,10) DEFAULT 0 NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FPICTURE') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FPICTURE VARCHAR(255) DEFAULT ' ' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FAUTOCLOSE') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FAUTOCLOSE CHAR(1) DEFAULT '0' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FAUTOJOB') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FAUTOJOB CHAR(1) DEFAULT '0' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FNRCCONTROL') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FNRCCONTROL CHAR(1) DEFAULT '0' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FPRINTSWS') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FPRINTSWS CHAR(1) DEFAULT '0' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FDIFSUPBEGINDATE') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FDIFSUPBEGINDATE DATETIME);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FDIFSUPENDDATE') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FDIFSUPENDDATE DATETIME);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FSUPUSER') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FSUPUSER BIGINT DEFAULT 0 NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FPARTNO') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FPARTNO VARCHAR(50) DEFAULT ' ' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FWORKCONTENT') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FWORKCONTENT VARCHAR(255) DEFAULT ' ' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FISNEEDJOB') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FISNEEDJOB CHAR(1) DEFAULT '0' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FISARCAPPROVAL') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FISARCAPPROVAL CHAR(1) DEFAULT '0' NOT NULL);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PMPD_PROJECT_MCC' AND KSQL_COL_NAME ='FPROJECTTYPE') 
ALTER TABLE T_PMPD_PROJECT_MCC ADD (FPROJECTTYPE VARCHAR(50) DEFAULT ' ' NOT NULL);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_FMM_PROJECT_HOURS')
CREATE TABLE T_FMM_PROJECT_HOURS
(
	FID 					        BIGINT 	                   DEFAULT 0   NOT NULL, 		
	FENTRYID        	            BIGINT 	                   DEFAULT 0   NOT NULL,       
	FSEQ           		            INT  	               	   DEFAULT 0   NOT NULL,       
	FHOURTYPE						VARCHAR(50)                DEFAULT ' ' NOT NULL,
	FBASICHOUR						DECIMAL(23,10)             DEFAULT 0   NOT NULL,
	FNRCHOUR						DECIMAL(23,10)             DEFAULT 0   NOT NULL,
	FSKILLHOUR						DECIMAL(23,10)             DEFAULT 0   NOT NULL,
	FNOSKILLHOUR					DECIMAL(23,10)             DEFAULT 0   NOT NULL,
	FTOTALHOUR						DECIMAL(23,10)             DEFAULT 0   NOT NULL
);

EXEC P_ALTERPK 'PK_FMM_PROJECT_HOURS', 'T_FMM_PROJECT_HOURS', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_FMM_PROJECT_HOURS_FS') CREATE INDEX IDX_FMM_PROJECT_HOURS_FS ON T_FMM_PROJECT_HOURS ( FID ,FSEQ );


