/**Begin D:\PDM_UPGRADE\PDM1\HAOS_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_HAOS_ORGTEAM' AND KSQL_COL_NAME IN ('FSOURCEORGID')) 
 ALTER TABLE T_HAOS_ORGTEAM ADD (FSOURCEORGID BIGINT DEFAULT 0 NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_CUSTOMOTSTRUCT') 
 CREATE TABLE T_HAOS_CUSTOMOTSTRUCT (
FID BIGINT DEFAULT 0 NOT NULL,
FORGTEAMID BIGINT DEFAULT 0 NOT NULL,
FPARENTID BIGINT DEFAULT 0 NOT NULL,
FLEVEL INT DEFAULT 0 NOT NULL,
FISLEAF CHAR(1) DEFAULT '0' NOT NULL,
FSTRUCTLONGNUMBER VARCHAR(500) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FLONGNUMBER VARCHAR(500) DEFAULT ' ' NOT NULL,
FINDEX INT DEFAULT 0 NOT NULL,
FISSYSPRESET VARCHAR(1) DEFAULT '0' NOT NULL,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FBOID BIGINT DEFAULT 0 NOT NULL,
FISCURRENTVERSION VARCHAR(1) DEFAULT '0' NOT NULL,
FBSED DATETIME,
FBSLED DATETIME,
FBRED DATETIME,
FBRLED DATETIME,
FDATASTATUS VARCHAR(2) DEFAULT ' ' NOT NULL,
FSOURCEVID BIGINT DEFAULT 0 NOT NULL,
FISMODIFY VARCHAR(1) DEFAULT '0' NOT NULL,
FFIRSTBSED DATETIME,
FCHANGEBSED DATETIME,
FBRFD DATETIME,
FENABLE VARCHAR(2) DEFAULT '1' NOT NULL,
FSTATUS VARCHAR(2) DEFAULT ' C' NOT NULL,
FINITSTATUS VARCHAR(2) DEFAULT '2' NOT NULL,
FINITDATASOURCE VARCHAR(2) DEFAULT '0' NOT NULL,
FINITBATCH BIGINT DEFAULT 0 NOT NULL,
FHISVERSION VARCHAR(10) DEFAULT ' ' NOT NULL,
FCHANGEDESCRIPTION VARCHAR(255) DEFAULT ' ' NOT NULL,
FORGTEAMHISID BIGINT DEFAULT 0 NOT NULL,
FOTCLASSIFYID BIGINT DEFAULT 0 NOT NULL,
FSTRUCTPROJECTID BIGINT DEFAULT 0 NOT NULL,
FISROOT CHAR(1) DEFAULT '0' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_CUSTOMOTSORT') 
 CREATE TABLE T_HAOS_CUSTOMOTSORT (
FID BIGINT DEFAULT 0 NOT NULL,
FORGTEAMID BIGINT DEFAULT 0 NOT NULL,
FINDEX INT DEFAULT 0 NOT NULL,
FSORTCODE VARCHAR(500) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(2) DEFAULT ' C' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FENABLE VARCHAR(2) DEFAULT '1' NOT NULL,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FISSYSPRESET VARCHAR(1) DEFAULT '0' NOT NULL,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FBOID BIGINT DEFAULT 0 NOT NULL,
FISCURRENTVERSION VARCHAR(1) DEFAULT '0' NOT NULL,
FBSED DATETIME,
FBSLED DATETIME,
FBRED DATETIME,
FBRLED DATETIME,
FDATASTATUS VARCHAR(2) DEFAULT ' ' NOT NULL,
FSOURCEVID BIGINT DEFAULT 0 NOT NULL,
FISMODIFY VARCHAR(1) DEFAULT '0' NOT NULL,
FFIRSTBSED DATETIME,
FCHANGEBSED DATETIME,
FBRFD DATETIME,
FINITSTATUS VARCHAR(2) DEFAULT '2' NOT NULL,
FINITDATASOURCE VARCHAR(2) DEFAULT '0' NOT NULL,
FINITBATCH BIGINT DEFAULT 0 NOT NULL,
FHISVERSION VARCHAR(10) DEFAULT ' ' NOT NULL,
FCHANGEDESCRIPTION VARCHAR(255) DEFAULT ' ' NOT NULL,
FSTRUCTPROJECTID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_HAOS_STRUCTPROJECT' AND KSQL_COL_NAME IN ('FISTOALLAREAS')) 
 ALTER TABLE T_HAOS_STRUCTPROJECT ADD (FISTOALLAREAS CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_HAOS_STRUCTPROJECT' AND KSQL_COL_NAME IN ('FISSYNCORG')) 
 ALTER TABLE T_HAOS_STRUCTPROJECT ADD (FISSYNCORG CHAR(1) DEFAULT '0' NOT NULL );
 
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_STRUCTTYPE') 
 CREATE TABLE T_HAOS_STRUCTTYPE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(60) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FSTATUS VARCHAR(2) DEFAULT 'C' NOT NULL,
FENABLE VARCHAR(2) DEFAULT '1' NOT NULL,
FISSYSPRESET CHAR(1) DEFAULT '0' NOT NULL,
FINDEX INT DEFAULT 0 NOT NULL,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_STRUCTTYPE_L') 
 CREATE TABLE T_HAOS_STRUCTTYPE_L (
FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_STRUCTPROENTRY') 
 CREATE TABLE T_HAOS_STRUCTPROENTRY (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FSTRUCTPROJECTID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_CUSTOMOROLE') 
 CREATE TABLE T_HAOS_CUSTOMOROLE (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(60) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FSTATUS VARCHAR(2) DEFAULT 'C' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FENABLE VARCHAR(2) DEFAULT '1' NOT NULL,
FCREATETIME DATETIME,
FMODIFYTIME DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL,
FSIMPLENAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FINDEX INT DEFAULT 0 NOT NULL,
FISSYSPRESET CHAR(1) DEFAULT '0' NOT NULL,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FBOID BIGINT DEFAULT 0 NOT NULL,
FISCURRENTVERSION VARCHAR(1) DEFAULT '0' NOT NULL,
FBSED DATETIME,
FBSLED DATETIME,
FDATASTATUS VARCHAR(2) DEFAULT ' ' NOT NULL,
FSOURCEVID BIGINT DEFAULT 0 NOT NULL,
FFIRSTBSED DATETIME,
FCHANGEBSED DATETIME,
FISMODIFY VARCHAR(1) DEFAULT '0' NOT NULL,
FBRED DATETIME,
FBRLED DATETIME,
FHISVERSION VARCHAR(10) DEFAULT ' ' NOT NULL,
FBRFD DATETIME,
FORGTEAMID BIGINT DEFAULT 0 NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_CUSTOMOROLE_L') 
 CREATE TABLE T_HAOS_CUSTOMOROLE_L (
FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_CUSEMPPOSORGREL') 
 CREATE TABLE T_HAOS_CUSEMPPOSORGREL (
FID BIGINT DEFAULT 0 NOT NULL,
FEMPLOYEEID BIGINT DEFAULT 0 NOT NULL,
FPERSONID BIGINT DEFAULT 0 NOT NULL,
FORGTEAMID BIGINT DEFAULT 0 NOT NULL,
FOUTPERSONID BIGINT DEFAULT 0 NOT NULL,
FCUSTOMOROLEID BIGINT DEFAULT 0 NOT NULL,
FISCHARGE CHAR(1) DEFAULT '0' NOT NULL,
FSTARTDATE DATETIME,
FSYSENDDATE DATETIME,
FNUMBER VARCHAR(60) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FDATASOURCE VARCHAR(2) DEFAULT '1' NOT NULL,
FBUSINESSSTATUS VARCHAR(2) DEFAULT '1' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FBOID BIGINT DEFAULT 0 NOT NULL,
FISCURRENTVERSION CHAR(1) DEFAULT '1' NOT NULL,
FDATASTATUS VARCHAR(2) DEFAULT '1' NOT NULL,
FSOURCEVID BIGINT DEFAULT 0 NOT NULL,
FISMODIFY CHAR(1) DEFAULT '0' NOT NULL,
FBSED DATETIME,
FBSLED DATETIME,
FBRED DATETIME,
FBRLED DATETIME,
FFIRSTBSED DATETIME,
FCHANGEBSED DATETIME,
FBRFD DATETIME,
FHISVERSION VARCHAR(10) DEFAULT ' ' NOT NULL,
FINITSTATUS VARCHAR(2) DEFAULT '2' NOT NULL,
FINITDATASOURCE VARCHAR(2) DEFAULT '0' NOT NULL,
FINITBATCH BIGINT DEFAULT 0 NOT NULL,
FINDEX INT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_OUTPERSON') 
 CREATE TABLE T_HAOS_OUTPERSON (
FID BIGINT DEFAULT 0 NOT NULL,
FNUMBER VARCHAR(60) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FGENDERID BIGINT DEFAULT 0 NOT NULL,
FPHONE VARCHAR(30) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FMODIFYTIME DATETIME,
FSTATUS VARCHAR(2) DEFAULT 'C' NOT NULL,
FENABLE VARCHAR(2) DEFAULT '1' NOT NULL,
FISSYSPRESET CHAR(1) DEFAULT '0' NOT NULL,
FINDEX INT DEFAULT 0 NOT NULL,
FDISABLERID BIGINT DEFAULT 0 NOT NULL,
FDISABLEDATE DATETIME,
FMASTERID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_OUTPERSON_L') 
 CREATE TABLE T_HAOS_OUTPERSON_L (
FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSIMPLENAME NVARCHAR(100) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_HAOS_CUSEMPPOSORGREL_L') 
 CREATE TABLE T_HAOS_CUSEMPPOSORGREL_L (
FPKID VARCHAR(18) DEFAULT ' ' NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FLOCALEID VARCHAR(10) DEFAULT ' ' NOT NULL,
FDESCRIPTION NVARCHAR(255) DEFAULT ' ' NOT NULL,
FNAME NVARCHAR(100) DEFAULT ' ' NOT NULL
);



/**End D:\PDM_UPGRADE\PDM1\HAOS_table.sql **/
