/**Begin C:\Users\rd_zhixiong_w\Downloads\PDM_UPGRADE\PDM1\TBO_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TBO_PLINFO_E' AND KSQL_COL_NAME IN ('FFOREXSWAPTYPE'))
 ALTER TABLE T_TBO_PLINFO_E ADD (FFOREXSWAPTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TBO_PLINFO_E' AND KSQL_COL_NAME IN ('FTRADEBIZDATE'))
 ALTER TABLE T_TBO_PLINFO_E ADD (FTRADEBIZDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TBO_PLINFO_HISTORY' AND KSQL_COL_NAME IN ('FBILLNO'))
 ALTER TABLE T_TBO_PLINFO_HISTORY ADD (FBILLNO NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TBO_PLINFO_HISTORY' AND KSQL_COL_NAME IN ('FPROVISION'))
 ALTER TABLE T_TBO_PLINFO_HISTORY ADD (FPROVISION CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TBO_PLINFO_HISTORY' AND KSQL_COL_NAME IN ('FPLPROVISIONID'))
 ALTER TABLE T_TBO_PLINFO_HISTORY ADD (FPLPROVISIONID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TBO_PLINFO_HISTORY' AND KSQL_COL_NAME IN ('FPLPROVISIONCURRENCYID'))
 ALTER TABLE T_TBO_PLINFO_HISTORY ADD (FPLPROVISIONCURRENCYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TBO_PLINFO_HISTORY' AND KSQL_COL_NAME IN ('FPLPROVISIONAMT'))
 ALTER TABLE T_TBO_PLINFO_HISTORY ADD (FPLPROVISIONAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TBO_PL_PROVIS_PRODUCTS')
 CREATE TABLE T_TBO_PL_PROVIS_PRODUCTS (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TBO_PL_PROVISION')
 CREATE TABLE T_TBO_PL_PROVISION (
FID BIGINT DEFAULT 0 NOT NULL,
FBILLNO NVARCHAR(80) DEFAULT ' ' NOT NULL,
FBILLSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCREATORID BIGINT DEFAULT 0 NOT NULL,
FMODIFIERID BIGINT DEFAULT 0 NOT NULL,
FAUDITORID BIGINT DEFAULT 0 NOT NULL,
FAUDITDATE DATETIME,
FMODIFYTIME DATETIME,
FCREATETIME DATETIME,
FORGID BIGINT DEFAULT 0 NOT NULL,
FTYPE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FPROVISIONDATE DATETIME,
FPLCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FLOCALCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FPLPROVISIONCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FREMARK NVARCHAR(255) DEFAULT ' ' NOT NULL,
FTOTALPROVISIONAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWRITEOFFAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FWRITEOFFSTATUS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSOURCEBILLID BIGINT DEFAULT 0 NOT NULL,
FWRITEOFFBILLID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TBO_PL_PROVISION_ENTRY') 
 CREATE TABLE T_TBO_PL_PROVISION_ENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FPLCURRENCYFLOATPLAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FLOCALCURRENCYFLOATPLAMT DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPLINFOID BIGINT DEFAULT 0 NOT NULL,
FTRADEBILLID BIGINT DEFAULT 0 NOT NULL,
FTRADETYPEID BIGINT DEFAULT 0 NOT NULL
);



/**End C:\Users\rd_zhixiong_w\Downloads\PDM_UPGRADE\PDM1\TBO_table.sql **/
