/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\ER_table.sql **/


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_ER_PUBINVOICEANDEXPENSE') 
 CREATE TABLE T_ER_PUBINVOICEANDEXPENSE (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FEXPENSEENTRYID BIGINT DEFAULT 0 NOT NULL,
FINVOICEENTRYID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMBILL' AND KSQL_COL_NAME ='FAUTOMAPINVOICE') 
 ALTER TABLE T_ER_PUBREIMBILL ADD (FAUTOMAPINVOICE CHAR(1) DEFAULT '1' NOT NULL );

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_ER_PUBREIMINVOICEINFO' AND KSQL_COL_NAME ='FISMAPEXPENSE') 
 ALTER TABLE T_ER_PUBREIMINVOICEINFO ADD (FISMAPEXPENSE CHAR(1) DEFAULT '1' NOT NULL );


/*创建主键和索引*/
 EXEC P_ALTERPK 'PK_T_ER_PUBINVOICEANDEXPENSE', 'T_ER_PUBINVOICEANDEXPENSE', 'FENTRYID', '0';

 IF NOT EXISTS (SELECT 1 FROM KSQL_INDEXES WHERE KSQL_INDNAME = 'IDX_PUBINVOICEANDEXPENSE_ID') CREATE  CLUSTERED INDEX IDX_PUBINVOICEANDEXPENSE_ID ON T_ER_PUBINVOICEANDEXPENSE ( FID );



/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\ER_table.sql **/
