IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_BUSIBILL')
CREATE TABLE T_ER_BUSIBILL (
                               FID BIGINT DEFAULT 0 NOT NULL,
                               FBILLNO VARCHAR(50) DEFAULT ' ' NOT NULL,
                               FSERVER BIGINT DEFAULT 0 NOT NULL,
                               FUSER BIGINT DEFAULT 0 NOT NULL,
                               FCOMPANY BIGINT DEFAULT 0 NOT NULL,
                               FDEPT BIGINT DEFAULT 0 NOT NULL,
                               FHAPPENDDATE DATETIME,
                               FBILLPERIOD DATETIME,
                               FACCOUT VARCHAR(50) DEFAULT ' ' NOT NULL,
                               FCARDNUMBER VARCHAR(50) DEFAULT ' ' NOT NULL,
                               FBUSIDATE DATETIME,
                               FBUSIAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                               FCURRENCY BIGINT DEFAULT 0 NOT NULL,
                               FBUSINAME VARCHAR(50) DEFAULT ' ' NOT NULL,
                               FBUSITYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
                               FMODIFYTIME DATETIME,
                               FCREATETIME DATETIME,
                               FAUDITDATE DATETIME,
                               FCREATORID BIGINT DEFAULT 0 NOT NULL,
                               FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
                               FAUDITORID BIGINT DEFAULT 0 NOT NULL,
                               FBILLSTATUS VARCHAR(50) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_BUSIBILL', 'T_ER_BUSIBILL', 'FID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BUSI_SERVER') CREATE INDEX IDX_BUSI_SERVER ON T_ER_BUSIBILL ( FSERVER );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BUSI_USER') CREATE INDEX IDX_BUSI_USER ON T_ER_BUSIBILL ( FUSER );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BUSI_COMPANY') CREATE  CLUSTERED INDEX IDX_BUSI_COMPANY ON T_ER_BUSIBILL ( FCOMPANY ,FDEPT );

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_BUSI_AC') CREATE INDEX IDX_BUSI_AC ON T_ER_BUSIBILL ( FACCOUT ,FCARDNUMBER );

