/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\ER_table.sql **/
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_ER_CHECKINGPAYENTRY', 'FENTRYPAYAMOUNT', 'NULL', 'NULL', '1001', 'NULL';

 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_ER_CHECKINGPAYENTRY', 'FDESC', 'NULL', 'NULL', '1001', 'NULL';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAYENTRY' AND KSQL_COL_NAME ='FCHECKINGBILLNUM') 
 ALTER TABLE T_ER_CHECKINGPAYENTRY ADD (FCHECKINGBILLNUM VARCHAR(100) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAYENTRY' AND KSQL_COL_NAME ='FDEPT') 
 ALTER TABLE T_ER_CHECKINGPAYENTRY ADD (FDEPT BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAYENTRY' AND KSQL_COL_NAME ='FUSERID') 
 ALTER TABLE T_ER_CHECKINGPAYENTRY ADD (FUSERID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAYENTRY' AND KSQL_COL_NAME ='FTAXRATE') 
 ALTER TABLE T_ER_CHECKINGPAYENTRY ADD (FTAXRATE DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAYENTRY' AND KSQL_COL_NAME ='FTAXAMOUNT') 
 ALTER TABLE T_ER_CHECKINGPAYENTRY ADD (FTAXAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAYENTRY' AND KSQL_COL_NAME ='FNOTAXORIAMOUNT') 
 ALTER TABLE T_ER_CHECKINGPAYENTRY ADD (FNOTAXORIAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAYENTRY' AND KSQL_COL_NAME ='FACTENTRYAMOUNT') 
 ALTER TABLE T_ER_CHECKINGPAYENTRY ADD (FACTENTRYAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAYENTRY' AND KSQL_COL_NAME ='FSERVICEITEM') 
 ALTER TABLE T_ER_CHECKINGPAYENTRY ADD (FSERVICEITEM VARCHAR(10) DEFAULT ' ' NOT NULL );
 
 /**商旅付款申请单分录关联表 **/
 IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_CHECKINGPAYENTRY_LK') 
 CREATE TABLE T_ER_CHECKINGPAYENTRY_LK (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FPKID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FSTABLEID BIGINT DEFAULT 0 NOT NULL,
FSBILLID BIGINT DEFAULT 0 NOT NULL,
FSID BIGINT DEFAULT 0 NOT NULL
);

 EXEC P_ALTERPK 'PK_T_ER_CHECKINGPAYENTRY_LK', 'T_ER_CHECKINGPAYENTRY_LK', 'FPKID', '1';

IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_ER_CHECKINGPAYENTRY_LK_FK') CREATE INDEX IDX_ER_CHECKINGPAYENTRY_LK_FK ON T_ER_CHECKINGPAYENTRY_LK ( FENTRYID );
 
 /**商旅付款申请单添加申请日期、服务商字段类型调整 **/
 EXEC P_AlterColumn 'T_ER_CHECKINGPAY', 'FSERVER', 'VARCHAR(100)', 'NOT NULL', '1111', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_CHECKINGPAY' AND KSQL_COL_NAME ='FBIZDATE') 
 ALTER TABLE T_ER_CHECKINGPAY ADD (FBIZDATE DATETIME );
/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\ER_table.sql **/
