/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\IM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURRECBILLENTRY_D' AND KSQL_COL_NAME IN ('FOUTOWNERTYPE')) 
 ALTER TABLE T_IM_PURRECBILLENTRY_D ADD (FOUTOWNERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURRECBILLENTRY_D' AND KSQL_COL_NAME IN ('FOUTOWNERID')) 
 ALTER TABLE T_IM_PURRECBILLENTRY_D ADD (FOUTOWNERID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURRECBILLENTRY_D' AND KSQL_COL_NAME IN ('FOUTKEEPERTYPE')) 
 ALTER TABLE T_IM_PURRECBILLENTRY_D ADD (FOUTKEEPERTYPE NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURRECBILLENTRY_D' AND KSQL_COL_NAME IN ('FOUTKEEPERID')) 
 ALTER TABLE T_IM_PURRECBILLENTRY_D ADD (FOUTKEEPERID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY' AND KSQL_COL_NAME IN ('FOUTINVTYPEID')) 
 ALTER TABLE T_IM_PURINBILLENTRY ADD (FOUTINVTYPEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY' AND KSQL_COL_NAME IN ('FOUTINVSTATUSID')) 
 ALTER TABLE T_IM_PURINBILLENTRY ADD (FOUTINVSTATUSID BIGINT DEFAULT 0 NOT NULL );
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_IM_PURINBILLENTRY', 'FENTRYDC', 'NULL', 'NULL', '1001', 'NULL';

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

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

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PRODUCTINBILL' AND KSQL_COL_NAME IN ('FBIZTIMES')) 
 ALTER TABLE T_IM_PRODUCTINBILL ADD (FBIZTIMES DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PRODUCTINBILL' AND KSQL_COL_NAME IN ('FBIZTYPEIDS')) 
 ALTER TABLE T_IM_PRODUCTINBILL ADD (FBIZTYPEIDS BIGINT DEFAULT 0 NOT NULL );
 --- drop column --------- 请认真检查该脚本 ------------------- 
 EXEC p_AlterColumn 'T_IM_PRODUCTINBILL', 'FBIZTIME', 'NULL', 'NULL', '1001', 'NULL';

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

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_TRANSAPPLYSNENTRY') 
 CREATE TABLE T_IM_TRANSAPPLYSNENTRY (
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSERIALNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSERIALCOMMENT NVARCHAR(512) DEFAULT ' ' NOT NULL,
FSERIALID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_IM_PRODUCTINSNENTRY') 
 CREATE TABLE T_IM_PRODUCTINSNENTRY (
FDETAILID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FSERIALNUMBER NVARCHAR(100) DEFAULT ' ' NOT NULL,
FSERIALCOMMENT NVARCHAR(512) DEFAULT ' ' NOT NULL,
FSERIALID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY_R' AND KSQL_COL_NAME IN ('FJOINPRICEBASEQTY')) 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FJOINPRICEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURINBILLENTRY_R' AND KSQL_COL_NAME IN ('FREMAINJOINPRICEBASEQTY')) 
 ALTER TABLE T_IM_PURINBILLENTRY_R ADD (FREMAINJOINPRICEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_MREQBILLENTRY' AND KSQL_COL_NAME IN ('FMATERIALMASTERID')) 
 ALTER TABLE T_IM_MREQBILLENTRY ADD (FMATERIALMASTERID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILLENTRY_R' AND KSQL_COL_NAME IN ('FJOINPRICEBASEQTY')) 
 ALTER TABLE T_IM_SALOUTBILLENTRY_R ADD (FJOINPRICEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_SALOUTBILLENTRY_R' AND KSQL_COL_NAME IN ('FREMAINJOINPRICEBASEQTY')) 
 ALTER TABLE T_IM_SALOUTBILLENTRY_R ADD (FREMAINJOINPRICEBASEQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_IM_PURRECBILLENTRY_R' AND KSQL_COL_NAME IN ('FPURORDERBILLNUMBER')) 
 ALTER TABLE T_IM_PURRECBILLENTRY_R ADD (FPURORDERBILLNUMBER NVARCHAR(80) DEFAULT ' ' NOT NULL );

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