IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_INVOICELOG')
CREATE TABLE T_ER_INVOICELOG (
                                 FID BIGINT DEFAULT 0 NOT NULL,
                                 FUSERNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FOPNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FOPDESC NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FOPDATE DATETIME,
                                 FOPTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
                                 FLOGINFO NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FLOGINFO_TAG NCLOB DEFAULT ' ',
                                 FSERIALNO NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FBILLNO NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FINVOICENO NVARCHAR(255) DEFAULT ' ' NOT NULL,
                                 FTRACEID NVARCHAR(255) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_INVOICELOG', 'T_ER_INVOICELOG', 'FID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICELOG_USERNAME') CREATE INDEX IDX_ER_INVOICELOG_USERNAME ON T_ER_INVOICELOG ( FUSERNAME );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICELOG_DATE') CREATE INDEX IDX_ER_INVOICELOG_DATE ON T_ER_INVOICELOG ( FOPDATE );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICELOG_SERIAL') CREATE INDEX IDX_ER_INVOICELOG_SERIAL ON T_ER_INVOICELOG ( FSERIALNO );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICELOG_BILLNO') CREATE INDEX IDX_ER_INVOICELOG_BILLNO ON T_ER_INVOICELOG ( FBILLNO );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICELOG_INVOICENO') CREATE INDEX IDX_ER_INVOICELOG_INVOICENO ON T_ER_INVOICELOG ( FINVOICENO );

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_INVOICELOG_TRACEID') CREATE INDEX IDX_ER_INVOICELOG_TRACEID ON T_ER_INVOICELOG ( FTRACEID );