/**标准币种增加语句**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_STANDCURRENCY_SET')
CREATE TABLE T_ER_STANDCURRENCY_SET(
    FID             BIGINT       DEFAULT 0   NOT NULL,
    FNUMBER         NVARCHAR(50) DEFAULT ' ' NOT NULL,
    FNAME           NVARCHAR(50) DEFAULT ' ' NOT NULL,
    FSTATUS         VARCHAR(10)  DEFAULT ' ' NOT NULL,
    FCREATORID      BIGINT       DEFAULT 0   NOT NULL,
    FMODIFIERID     BIGINT       DEFAULT 0   NOT NULL,
    FENABLE         VARCHAR(10)  DEFAULT '0' NOT NULL,
    FCREATETIME     DATETIME,
    FMODIFYTIME     DATETIME,
    FMASTERID       BIGINT       DEFAULT 0   NOT NULL,
    FCOUNTRY        BIGINT       DEFAULT 0   NOT NULL,
    FCURRENCY       BIGINT       DEFAULT 0   NOT NULL,
    FSELFDEFINE     NVARCHAR(50) DEFAULT ' ' NOT NULL,
    FISPRESET       CHAR(1)      DEFAULT '0' NOT NULL,
    FCREATEORGID    BIGINT       DEFAULT 0   NOT NULL,
    FORGID          BIGINT       DEFAULT 0   NOT NULL,
    FCTRLSTRATEGY   VARCHAR(50)  DEFAULT ' ' NOT NULL,
    FSOURCEDATAID   BIGINT       DEFAULT 0   NOT NULL,
    FBITINDEX       BIGINT       DEFAULT 0   NOT NULL,
    FSOURCEBITINDEX BIGINT       DEFAULT 0   NOT NULL,
    FSRCCREATEORGID BIGINT       DEFAULT 0   NOT NULL
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_STANDCURRENCY_SET_L')
CREATE TABLE T_ER_STANDCURRENCY_SET_L(
    FID       BIGINT        DEFAULT 0   NOT NULL,
    FPKID     NVARCHAR(50)  DEFAULT ' ' NOT NULL,
    FNAME     NVARCHAR(100) DEFAULT ' ' NOT NULL,
    FLOCALEID NVARCHAR(50)  DEFAULT ' ' NOT NULL
);
/**主键及索引相关改动**/
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_TRIP_CURRENCY_NUMBER')
CREATE INDEX IDX_ER_TRIP_CURRENCY_NUMBER ON T_ER_STANDCURRENCY_SET (FNUMBER);
EXEC P_ALTERPK 'PK_T_ER_TRIP_CURRENCY_ID', 'T_ER_STANDCURRENCY_SET', 'FID', '1';
EXEC P_ALTERPK 'PK_T_ER_TRIP_CURRENCY_L_ID', 'T_ER_STANDCURRENCY_SET_L', 'FPKID', '1';

/**出差地域表增加字段**/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRIPAREA' AND KSQL_COL_NAME ='FISOTHERCITY')
ALTER TABLE T_ER_TRIPAREA ADD (FISOTHERCITY CHAR (1) DEFAULT '0' NOT NULL);

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

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_TRIPAREA_COUNTRY')
CREATE TABLE T_ER_TRIPAREA_COUNTRY(
    FID         BIGINT DEFAULT 0 NOT NULL,
    FPKID       BIGINT DEFAULT 0 NOT NULL,
    FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);

EXEC P_ALTERPK 'PK_ER_AREA_COUNTRY', 'T_ER_TRIPAREA_COUNTRY', 'FPKID', '1';
IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_AREA_COUNTRY')
CREATE INDEX IDX_ER_AREA_COUNTRY ON T_ER_TRIPAREA_COUNTRY (FID);

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


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_STANDCURRENCY_ENTRY')
CREATE TABLE T_ER_STANDCURRENCY_ENTRY(
FID                 BIGINT       DEFAULT 0   NOT NULL,
FSEQ                INT       DEFAULT 0   NOT NULL,
FENTRYID            BIGINT       DEFAULT 0   NOT NULL,
FEXPENSEITEM        BIGINT       DEFAULT 0   NOT NULL,
FENTRYCURRENCY      BIGINT       DEFAULT 0   NOT NULL
);
EXEC P_ALTERPK 'PK_ER_STANDCURRENCY_ENTRY', 'T_ER_STANDCURRENCY_ENTRY', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_STANDCUR_ENTRY_FID')
CREATE INDEX IDX_ER_STANDCUR_ENTRY_FID ON T_ER_STANDCURRENCY_ENTRY (FID);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_STANDCURRENCY_SET' AND KSQL_COL_NAME IN ('FAPPLYTOALL'))
 ALTER TABLE T_ER_STANDCURRENCY_SET ADD (FAPPLYTOALL CHAR(1) DEFAULT ' ' NOT NULL );



