IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_DAILYREIMWITHHOLDING')
CREATE TABLE T_ER_DAILYREIMWITHHOLDING (
                   FID BIGINT DEFAULT 0 NOT NULL,
                   FENTRYID BIGINT DEFAULT 0 NOT NULL,
                   FSEQ INT DEFAULT 0 NOT NULL,
                   FWITHHOLDINGBILLNO VARCHAR(100) DEFAULT '0' NOT NULL,
                   FWHPAYERNAME VARCHAR(200) DEFAULT ' ' NOT NULL,
                   FWHBIZDATE DATETIME,
                   FWHDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                   FWHBILLPAYERTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
                   FWHBILLPAYERID BIGINT DEFAULT 0 NOT NULL,
                   FSOURCEWHITEMID BIGINT DEFAULT 0 NOT NULL,
                   FWHEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
                   FWHCURRENCY BIGINT DEFAULT 0 NOT NULL,
                   FWHQUOTETYPE CHAR(1) DEFAULT '0' NOT NULL,
                   FORGIWHBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                   FWHBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                   FWHBURSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                   FWHBURSEDCURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                   FWITHHOLDINGTYPE BIGINT DEFAULT 0 NOT NULL,
                   FWHCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
                   FWHENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
                   FWHENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
                   FWHENTRYCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
                   FWHSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
                   FWHSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
                   FWHSRCBILLTYPE VARCHAR(200) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_DAILYREIMWITHHOLDING', 'T_ER_DAILYREIMWITHHOLDING', 'FENTRYID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_DAILY_WITHHOLDING_FID') CREATE INDEX IDX_ER_DAILY_WITHHOLDING_FID ON T_ER_DAILYREIMWITHHOLDING ( FID ,FSEQ );



IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PUBLICWITHHOLDING')
CREATE TABLE T_ER_PUBLICWITHHOLDING (
                FID BIGINT DEFAULT 0 NOT NULL,
                FENTRYID BIGINT DEFAULT 0 NOT NULL,
                FSEQ INT DEFAULT 0 NOT NULL,
                FWITHHOLDINGBILLNO VARCHAR(100) DEFAULT '0' NOT NULL,
                FWHPAYERNAME VARCHAR(200) DEFAULT ' ' NOT NULL,
                FWHBIZDATE DATETIME,
                FWHDESCRIPTION NVARCHAR(1000) DEFAULT ' ' NOT NULL,
                FWHBILLPAYERTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
                FWHBILLPAYERID BIGINT DEFAULT 0 NOT NULL,
                FSOURCEWHITEMID BIGINT DEFAULT 0 NOT NULL,
                FWHEXCHANGERATE DECIMAL(23,10) DEFAULT 0 NOT NULL,
                FWHCURRENCY BIGINT DEFAULT 0 NOT NULL,
                FWHQUOTETYPE CHAR(1) DEFAULT '0' NOT NULL,
                FORGIWHBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                FWHBALANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                FWHBURSEDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                FWHBURSEDCURRAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
                FWITHHOLDINGTYPE BIGINT DEFAULT 0 NOT NULL,
                FWHCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
                FWHENTRYCOSTDEPTID BIGINT DEFAULT 0 NOT NULL,
                FWHENTRYCOSTCOMPANYID BIGINT DEFAULT 0 NOT NULL,
                FWHENTRYCOSTCENTERID BIGINT DEFAULT 0 NOT NULL,
                FWHSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
                FWHSOURCEENTRYID BIGINT DEFAULT 0 NOT NULL,
                FWHSRCBILLTYPE VARCHAR(200) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_T_ER_PUBLICWITHHOLDING', 'T_ER_PUBLICWITHHOLDING', 'FENTRYID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_PUBREIM_WITHHOLDING_FID') CREATE INDEX IDX_ER_PUBREIM_WITHHOLDING_FID ON T_ER_PUBLICWITHHOLDING ( FID ,FSEQ );

