/** 出差地域改用带组织的模板, 添加控制策略字段, 并添加EXC表和USEREG表, 创建人: 白文海; 创建时间: 2020年10月27日16:29:24 **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRIPTYPE' AND KSQL_COL_NAME ='FCTRLSTRATEGY') 
 ALTER TABLE T_ER_TRIPTYPE ADD (FCTRLSTRATEGY VARCHAR(10) DEFAULT ' ' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIPTYPEEXC') 
 CREATE TABLE T_ER_TRIPTYPEEXC (
FDATAID BIGINT DEFAULT 0 NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FUSEORGID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIPTYPEUSEREG') 
 CREATE TABLE T_ER_TRIPTYPEUSEREG (
FUSEORGID BIGINT DEFAULT 0 NOT NULL,
FDATAID BIGINT DEFAULT 0 NOT NULL,
FCREATEORGID BIGINT DEFAULT 0 NOT NULL,
FADMINORGID BIGINT DEFAULT 0 NOT NULL,
FCTRLSTRATEGY VARCHAR(10) DEFAULT ' ' NOT NULL,
FISASSIGN CHAR(1) DEFAULT '1' NOT NULL
);

 EXEC P_ALTERPK 'PK_T_ER_TRIPTYPEEXC', 'T_ER_TRIPTYPEEXC', 'FDATAID,FUSEORGID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRIPTYPE_UO') CREATE INDEX IDX_ER_TRIPTYPE_UO ON T_ER_TRIPTYPEEXC ( FUSEORGID );

 EXEC P_ALTERPK 'PK_T_ER_TRIPTYPEUSEREG', 'T_ER_TRIPTYPEUSEREG', 'FUSEORGID,FDATAID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRIPTYPE_FAMID') CREATE INDEX IDX_ER_TRIPTYPE_FAMID ON T_ER_TRIPTYPEUSEREG ( FADMINORGID );

