IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_BILLING_WRITEOFF') 
 CREATE TABLE T_ER_BILLING_WRITEOFF (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLINGID BIGINT DEFAULT 0 NOT NULL,
FTENTRYID BIGINT DEFAULT 0 NOT NULL,
FTID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FENTITYTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FOPERATETYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FCREATETIME DATETIME,
FEXECINOUTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FINOUTAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXECOFFSETAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FOFFSETAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FEXECAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FDESC NVARCHAR(1024) DEFAULT ' ' NOT NULL,
FREASONFORTRANSFEROUT NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCURRENCY BIGINT DEFAULT 0 NOT NULL,
FSTATUS NVARCHAR(1) DEFAULT ' ' NOT NULL,
FJSONDATA NVARCHAR(1024) DEFAULT ' ' NOT NULL,
FJSONDATA_TAG NCLOB,
FRULEVERSION BIGINT DEFAULT 0 NOT NULL
);


 EXEC P_ALTERPK 'PK_T_ER_BILLING_WRITEOFF', 'T_ER_BILLING_WRITEOFF', 'FID', '1';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_BILLINGID') CREATE INDEX IDX_ER_BILLINGID ON T_ER_BILLING_WRITEOFF ( FBILLINGID );

