/**Begin D:\PDM_UPGRADE\PDM1\TM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BIZRECORD_ENTRY' AND KSQL_COL_NAME IN ('FRECAMOUNT'))
 ALTER TABLE T_TM_BIZRECORD_ENTRY ADD (FRECAMOUNT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FPAYRATEFIXDATE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FPAYRATEFIXDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FPAYREFRATEID'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FPAYREFRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FPAYREFRATEDATE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FPAYREFRATEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FPAYREFRATEVALUE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FPAYREFRATEVALUE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FPAYFIXRATE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FPAYFIXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FPAYRATEMARGIN'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FPAYRATEMARGIN DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FPAYTOTALRATE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FPAYTOTALRATE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FPAYCASHFLOWID'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FPAYCASHFLOWID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FRECRATEFIXDATE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FRECRATEFIXDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FRECREFRATEID'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FRECREFRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FRECREFRATEDATE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FRECREFRATEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FRECREFRATEVALUE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FRECREFRATEVALUE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FRECFIXRATE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FRECFIXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FRECRATEMARGIN'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FRECRATEMARGIN DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FRECTOTALRATE'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FRECTOTALRATE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FRECCASHFLOWID'))
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FRECCASHFLOWID BIGINT DEFAULT 0 NOT NULL );

/**End D:\PDM_UPGRADE\PDM1\TM_table.sql **/

/**Begin C:\Users\rd_zhixiong_w\Downloads\PDM_UPGRADE\PDM1\TM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FDAYS')) 
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FDAYS INT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_BUSINESSBILL_E' AND KSQL_COL_NAME IN ('FBREAKBARRIER')) 
 ALTER TABLE T_TM_BUSINESSBILL_E ADD (FBREAKBARRIER CHAR(1) DEFAULT '0' NOT NULL );

--利率互换添加互换类型（原字段和外汇掉期字段名字重复）
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FRATESWAPTYPE'))
 ALTER TABLE T_TM_TRADE_S ADD (FRATESWAPTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
-- 互换买入结算页签添加损益字段
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_E' AND KSQL_COL_NAME IN ('FPLCURRENCYID'))
 ALTER TABLE T_TM_TRADE_E ADD (FPLCURRENCYID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_E' AND KSQL_COL_NAME IN ('FFXQUOTE'))
 ALTER TABLE T_TM_TRADE_E ADD (FFXQUOTE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_E' AND KSQL_COL_NAME IN ('FSPOTRATE'))
 ALTER TABLE T_TM_TRADE_E ADD (FSPOTRATE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_E' AND KSQL_COL_NAME IN ('FPLAMT'))
 ALTER TABLE T_TM_TRADE_E ADD (FPLAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_E' AND KSQL_COL_NAME IN ('FBASEFQ'))
 ALTER TABLE T_TM_TRADE_E ADD (FBASEFQ NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_E' AND KSQL_COL_NAME IN ('FBASEEXRATE'))
 ALTER TABLE T_TM_TRADE_E ADD (FBASEEXRATE DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_E' AND KSQL_COL_NAME IN ('FBASEPLAMT'))
 ALTER TABLE T_TM_TRADE_E ADD (FBASEPLAMT DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_E' AND KSQL_COL_NAME IN ('FBASECURRENCYID'))
 ALTER TABLE T_TM_TRADE_E ADD (FBASECURRENCYID BIGINT DEFAULT 0 NOT NULL );