/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MRP_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANORDER' AND KSQL_COL_NAME ='FMATERIALPLANID') 
 ALTER TABLE T_MRP_PLANORDER ADD (FMATERIALPLANID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANORDER' AND KSQL_COL_NAME ='FMATERIALLOCK')
 ALTER TABLE T_MRP_PLANORDER ADD (FMATERIALLOCK CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANORDER' AND KSQL_COL_NAME ='FMATERIALSPREAD') 
 ALTER TABLE T_MRP_PLANORDER ADD (FMATERIALSPREAD CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANORDERENTRY' AND KSQL_COL_NAME ='FENTRYISREPLACE') 
 ALTER TABLE T_MRP_PLANORDERENTRY ADD (FENTRYISREPLACE CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANORDERENTRY' AND KSQL_COL_NAME ='FENTRYREPLACESTRA') 
 ALTER TABLE T_MRP_PLANORDERENTRY ADD (FENTRYREPLACESTRA NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANORDERENTRY' AND KSQL_COL_NAME ='FENTRYREPLACEMETHOD') 
 ALTER TABLE T_MRP_PLANORDERENTRY ADD (FENTRYREPLACEMETHOD NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANORDERENTRY' AND KSQL_COL_NAME ='FENTRYREPLACEMATERIAL') 
 ALTER TABLE T_MRP_PLANORDERENTRY ADD (FENTRYREPLACEMATERIAL CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANORDERENTRY' AND KSQL_COL_NAME ='FENTRYREPLACEPRIORITY') 
 ALTER TABLE T_MRP_PLANORDERENTRY ADD (FENTRYREPLACEPRIORITY INT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_PLANORDERENTRY' AND KSQL_COL_NAME ='FENTRYMATERIALPLANID') 
 ALTER TABLE T_MRP_PLANORDERENTRY ADD (FENTRYMATERIALPLANID BIGINT DEFAULT 0 NOT NULL );







IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FEXCEPTIONNUMBER') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FEXCEPTIONNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FSUPPLYORGID') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FSUPPLYORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FREQUIREORGID') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FREQUIREORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FREQPRIORITY') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FREQPRIORITY NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_CALDETAILENTRY' AND KSQL_COL_NAME ='FSUPPRIORITY') 
 ALTER TABLE T_MRP_CALDETAILENTRY ADD (FSUPPRIORITY NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PLANORDER_C') 
 CREATE TABLE T_MRP_PLANORDER_C (
FID BIGINT DEFAULT 0 NOT NULL,
FCMPLSETNUM DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCMPLSETRESULT NVARCHAR(30) DEFAULT ' ' NOT NULL,
FRQCMPLSETNUM DECIMAL(23,10) DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_PLANORDERENTRY_C') 
 CREATE TABLE T_MRP_PLANORDERENTRY_C (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSMULATOCCUP DECIMAL(23,10) DEFAULT 0 NOT NULL,
FCMPLSETPLAN BIGINT DEFAULT 0 NOT NULL,
FCMPLSTDMDNUM DECIMAL(23,10) DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL
);



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