IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_ALLORDERBILL' AND KSQL_COL_NAME IN ('FOABILLFORMID'))
ALTER TABLE T_ER_ALLORDERBILL ADD (FOABILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_ALLORDERBILL' AND KSQL_COL_NAME IN ('FREIMBILLFORMID'))
ALTER TABLE T_ER_ALLORDERBILL ADD (FREIMBILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PLANEBILL_A' AND KSQL_COL_NAME IN ('FOABILLFORMID'))
ALTER TABLE T_ER_PLANEBILL_A ADD (FOABILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PLANEBILL_A' AND KSQL_COL_NAME IN ('FREIMBILLFORMID'))
ALTER TABLE T_ER_PLANEBILL_A ADD (FREIMBILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_HOTELBILL' AND KSQL_COL_NAME IN ('FOABILLFORMID'))
ALTER TABLE T_ER_HOTELBILL ADD (FOABILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_HOTELBILL' AND KSQL_COL_NAME IN ('FREIMBILLFORMID'))
ALTER TABLE T_ER_HOTELBILL ADD (FREIMBILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRAINBILL' AND KSQL_COL_NAME IN ('FOABILLFORMID'))
ALTER TABLE T_ER_TRAINBILL ADD (FOABILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_TRAINBILL' AND KSQL_COL_NAME IN ('FREIMBILLFORMID'))
ALTER TABLE T_ER_TRAINBILL ADD (FREIMBILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_VEHICLEBILL' AND KSQL_COL_NAME IN ('FOABILLFORMID'))
ALTER TABLE T_ER_VEHICLEBILL ADD (FOABILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_VEHICLEBILL' AND KSQL_COL_NAME IN ('FREIMBILLFORMID'))
ALTER TABLE T_ER_VEHICLEBILL ADD (FREIMBILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_MEALBILL' AND KSQL_COL_NAME IN ('FOABILLFORMID'))
ALTER TABLE T_ER_MEALBILL ADD (FOABILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_MEALBILL' AND KSQL_COL_NAME IN ('FREIMBILLFORMID'))
ALTER TABLE T_ER_MEALBILL ADD (FREIMBILLFORMID VARCHAR(50) DEFAULT ' ' NOT NULL );
EXEC p_AlterColumn 'T_ER_PUBREIMEXPDET_A', 'FOTHERSTANDAMOUNT', 'DECIMAL(23,10)', 'NOT NULL', '0010', '0';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMEXPDET_A' AND KSQL_COL_NAME IN ('FTRIPBOOKAMOUNT'))
ALTER TABLE T_ER_PUBREIMEXPDET_A ADD (FTRIPBOOKAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMEXPDET_A' AND KSQL_COL_NAME IN ('FTRIPBOOKCURAMOUNT'))
ALTER TABLE T_ER_PUBREIMEXPDET_A ADD (FTRIPBOOKCURAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMEXPDET_A' AND KSQL_COL_NAME IN ('FISEXISTMONTHLY'))
ALTER TABLE T_ER_PUBREIMEXPDET_A ADD (FISEXISTMONTHLY CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMBILL' AND KSQL_COL_NAME IN ('FMONTHSETTLEAMOUNT'))
ALTER TABLE T_ER_PUBREIMBILL ADD (FMONTHSETTLEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PUBLICREMORDERENTRY')
CREATE TABLE T_ER_PUBLICREMORDERENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSERVER VARCHAR(50) DEFAULT ' ' NOT NULL,
FOPERATIONTYPE VARCHAR(50) DEFAULT ' ' NOT NULL,
FOABILLNUM NVARCHAR(255) DEFAULT ' ' NOT NULL,
FORDERDATE DATETIME,
FSOURCEBOOKEDID BIGINT DEFAULT 0 NOT NULL,
FORDERNUMBER VARCHAR(255) DEFAULT ' ' NOT NULL,
FPARENTORDERNUM VARCHAR(255) DEFAULT ' ' NOT NULL,
FORDERTYPE CHAR(1) DEFAULT ' ' NOT NULL,
FORDERSTATUSSTR NVARCHAR(50) DEFAULT ' ' NOT NULL,
FTICKETSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FTOTALAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTICKETPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSERVICEFEE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FREFUNDAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FASSURANCEAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAIRPORTPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FFUELPRICE DECIMAL(23,10) DEFAULT 0 NOT NULL,
FENDORSEMENTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTRAVELERNAME NVARCHAR(255) DEFAULT ' ' NOT NULL,
FFROMPLACE NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FTOPLACE NVARCHAR(2000) DEFAULT ' ' NOT NULL,
FBEGINTIME DATETIME,
FENDTIME DATETIME,
FORDERBOOKEDDEPT BIGINT DEFAULT 0 NOT NULL,
FORDERCOMPANY BIGINT DEFAULT 0 NOT NULL,
FORDERCOSTDEPT BIGINT DEFAULT 0 NOT NULL,
FORDERCOSTCOMPANY BIGINT DEFAULT 0 NOT NULL,
FORDERDEDUCTIBLETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FTICKETPRICEDEDUCTIBLETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSERVICEFEEDEDUCTIBLETAX DECIMAL(23,10) DEFAULT 0 NOT NULL,
FORDERCURRENCY BIGINT DEFAULT 0 NOT NULL,
FORDEXPENSEENTRYID BIGINT DEFAULT 0 NOT NULL,
FORDERFORMID VARCHAR(255) DEFAULT ' ' NOT NULL
);

EXEC P_ALTERPK 'PK_ER_PUBLICREMORDERENTRY', 'T_ER_PUBLICREMORDERENTRY', 'FENTRYID', '1';

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

