/**Begin D:\d_desk\pdm\PDM_UPGRADE_1.1\PDM_UPGRADE\pdm1\SIM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SIM_RECYCLE_LOG') 
 CREATE TABLE T_SIM_RECYCLE_LOG (
FID BIGINT DEFAULT 0 NOT NULL,
FTERMINAL NVARCHAR(50) DEFAULT ' ' NOT NULL,
FTERMINALNAME NVARCHAR(50) DEFAULT ' ' NOT NULL,
FTAX BIGINT DEFAULT 0 NOT NULL,
FEQINFO BIGINT DEFAULT 0 NOT NULL,
FCOPIES BIGINT DEFAULT 0 NOT NULL,
FHANDLERS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FRECYCLEDATE DATETIME,
FINVOICETYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FORG BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SIM_ROLLBACK_LOG') 
 CREATE TABLE T_SIM_ROLLBACK_LOG (
FID BIGINT DEFAULT 0 NOT NULL,
FEQINFO BIGINT DEFAULT 0 NOT NULL,
FTAX BIGINT DEFAULT 0 NOT NULL,
FINVOICECODE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSTARTNUM BIGINT DEFAULT 0 NOT NULL,
FENDNUM BIGINT DEFAULT 0 NOT NULL,
FHANDLERS NVARCHAR(50) DEFAULT ' ' NOT NULL,
FRECYCLEDATE DATETIME,
FINVOICETYPE NVARCHAR(30) DEFAULT ' ' NOT NULL,
FORG BIGINT DEFAULT 0 NOT NULL,
FCOPIES BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SIM_APPLY_RESULT') 
 CREATE TABLE T_SIM_APPLY_RESULT (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FINVOICECODE NVARCHAR(50) DEFAULT ' ' NOT NULL,
FSTARTNUM BIGINT DEFAULT 0 NOT NULL,
FENDNUM BIGINT DEFAULT 0 NOT NULL,
FCOPIES BIGINT DEFAULT 0 NOT NULL
);


 EXEC p_AlterColumn 'T_SIM_INV_APPLY_LOG', 'FAPPLYTYPE', 'NVARCHAR(30)', 'NOT NULL', '1111', ''' ''';

 EXEC p_AlterColumn 'T_SIM_INV_APPLY_LOG', 'FAGENT', 'BIGINT', 'NOT NULL', '1111', '0';

 EXEC p_AlterColumn 'T_SIM_INV_APPLY_LOG', 'FINVOICETYPE', 'NVARCHAR(30)', 'NOT NULL', '1111', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FNUM') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FNUM BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FTAX') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FTAX BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FDISPOSE') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FDISPOSE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FDISPOSEMSG') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FDISPOSEMSG NVARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FTEXTFIELD1') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FTEXTFIELD1 NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FNO') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FNO NVARCHAR(40) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FTYPE') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FMSG') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FMSG NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FDISPOSEDATE') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FDISPOSEDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FAPPLYDATE') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FAPPLYDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FINVOICEKINDCODE') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FINVOICEKINDCODE NVARCHAR(20) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FINVOICEKINDNAME') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FINVOICEKINDNAME NVARCHAR(20) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SIM_INV_APPLY_LOG' AND KSQL_COL_NAME ='FTERMINAL') 
 ALTER TABLE T_SIM_INV_APPLY_LOG ADD (FTERMINAL NVARCHAR(50) DEFAULT ' ' NOT NULL );

/**End D:\d_desk\pdm\PDM_UPGRADE_1.1\PDM_UPGRADE\pdm1\SIM_table.sql **/
