/**Begin D:\next\pdm_upgrade\pdm_upgrade\pdm1\TM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TM_TRADE_E') 
 CREATE TABLE T_TM_TRADE_E (
FID BIGINT DEFAULT 0 NOT NULL,
FRECRATETYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECCURRENCYID BIGINT DEFAULT 0 NOT NULL,
FRECMARKETID BIGINT DEFAULT 0 NOT NULL,
FRECAMOUNT DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FRECINITEXAMOUNT DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FRECENDEXAMOUNT DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FRECVALUEDATE DATETIME,
FRECBASIS NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECFIXEDRATE DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FRECPAYTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECDATEADJUSTMETHOD NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECPAYFREQUENCY NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECPAYDATETYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECDISCOUNT CHAR(1) DEFAULT ' ' NOT NULL,
FRECDELAY INT DEFAULT 0 NOT NULL,
FRECREFINDEXID BIGINT DEFAULT 0 NOT NULL,
FRECRATEMARGIN DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FRECRATERESETTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECRATEQUOTAFREQ NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECRATERESETFREQ NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECBEFOREINITDATE DATETIME,
FRECRATEADJUSTMETHOD NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECRATERESETOFFSET BIGINT DEFAULT 0 NOT NULL,
FRECFIRSTFIXEDDATE DATETIME,
FRECFIRSTFIXEDRATE DECIMAL(23,10) DEFAULT 0.0000000000 NOT NULL,
FRECSTUB CHAR(1) DEFAULT ' ' NOT NULL,
FRECSTUBTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRECFIRSTPAYCOPDATE DATETIME,
FRECFIRSTREFERRATE BIGINT DEFAULT 0 NOT NULL,
FRECPENUPAYCOPDATE DATETIME,
FRECPENUREFERRATE BIGINT DEFAULT 0 NOT NULL
);


 EXEC p_AlterColumn 'T_TM_TRADE_S', 'FFIXEDRATE', 'DECIMAL(23,10)', 'NOT NULL', '0001', '0.00000000';

 EXEC p_AlterColumn 'T_TM_TRADE_S', 'FFIRSTFIXEDRATE', 'DECIMAL(23,10)', 'NOT NULL', '0001', '0.00000000';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FINITPRIEXTYPE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FINITPRIEXTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FENDPRIEXTYPE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FENDPRIEXTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FTERM')) 
 ALTER TABLE T_TM_TRADE_S ADD (FTERM NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FENDADJMETHOD')) 
 ALTER TABLE T_TM_TRADE_S ADD (FENDADJMETHOD NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FADJUSTEDENDDATE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FADJUSTEDENDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FINITEXAMOUNT')) 
 ALTER TABLE T_TM_TRADE_S ADD (FINITEXAMOUNT DECIMAL(23,10) DEFAULT 0.00000000 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FENDEXAMOUNT')) 
 ALTER TABLE T_TM_TRADE_S ADD (FENDEXAMOUNT DECIMAL(23,10) DEFAULT 0.00000000 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FVALUEDATE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FVALUEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FPAYDATETYPE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FPAYDATETYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FDISCOUNT')) 
 ALTER TABLE T_TM_TRADE_S ADD (FDISCOUNT CHAR(1) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FDELAY')) 
 ALTER TABLE T_TM_TRADE_S ADD (FDELAY INT 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 ('FRATEMARGIN')) 
 ALTER TABLE T_TM_TRADE_S ADD (FRATEMARGIN DECIMAL(23,10) DEFAULT 0.00000000 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FRATERESETTYPE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FRATERESETTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FRATEQUOTAFREQ')) 
 ALTER TABLE T_TM_TRADE_S ADD (FRATEQUOTAFREQ NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FRATERESETFREQ')) 
 ALTER TABLE T_TM_TRADE_S ADD (FRATERESETFREQ NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FBEFOREINITDATE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FBEFOREINITDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FRATEADJUSTMETHOD')) 
 ALTER TABLE T_TM_TRADE_S ADD (FRATEADJUSTMETHOD NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FFIRSTFIXEDDATE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FFIRSTFIXEDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FSTUB')) 
 ALTER TABLE T_TM_TRADE_S ADD (FSTUB CHAR(1) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FFIRSTPAYCOPDATE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FFIRSTPAYCOPDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FFIRSTREFERRATE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FFIRSTREFERRATE BIGINT 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 ('FPENUPAYCOPDATE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FPENUPAYCOPDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FPENUREFERRATE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FPENUREFERRATE BIGINT 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 ('FNOMINALRATE')) 
 ALTER TABLE T_TM_TRADE_S ADD (FNOMINALRATE DECIMAL(23,10) DEFAULT 0.00000000 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FCURRENTRATE1')) 
 ALTER TABLE T_TM_TRADE_S ADD (FCURRENTRATE1 DECIMAL(23,10) DEFAULT 0.00000000 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FCURRENTRATE2')) 
 ALTER TABLE T_TM_TRADE_S ADD (FCURRENTRATE2 DECIMAL(23,10) DEFAULT 0.00000000 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_TM_TRADE_S' AND KSQL_COL_NAME IN ('FCURRENTRATE3')) 
 ALTER TABLE T_TM_TRADE_S ADD (FCURRENTRATE3 DECIMAL(23,10) DEFAULT 0.00000000 NOT NULL );


 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_TM_TRADE_PWC') 
 CREATE TABLE T_TM_TRADE_PWC (
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_TM_TRADE_RWC') 
 CREATE TABLE T_TM_TRADE_RWC (
FPKID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FBASEDATAID BIGINT DEFAULT 0 NOT NULL
);
 
/**End D:\next\pdm_upgrade\pdm_upgrade\pdm1\TM_table.sql **/
