/**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_SIMULATIONSUMMARY' AND KSQL_COL_NAME ='FALLQTY') 
 ALTER TABLE T_MRP_SIMULATIONSUMMARY ADD (FALLQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONSUMMARY' AND KSQL_COL_NAME ='FWAYCANQTY') 
 ALTER TABLE T_MRP_SIMULATIONSUMMARY ADD (FWAYCANQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONSUMMARY' AND KSQL_COL_NAME ='FWAYCURRENTQTY') 
 ALTER TABLE T_MRP_SIMULATIONSUMMARY ADD (FWAYCURRENTQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FLONGESTPATH') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FLONGESTPATH CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONCALCENTRY' AND KSQL_COL_NAME ='FORDERDATE') 
 ALTER TABLE T_MRP_SIMULATIONCALCENTRY ADD (FORDERDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FREQSOURCEBILLNO') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FREQSOURCEBILLNO NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FBILLID') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FBILLID NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FBILLENTRYID') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FBILLENTRYID NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FISREQUIRE') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FISREQUIRE CHAR(1) DEFAULT '0' NOT NULL );
 

IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_MRP_SIMULATEFIELDENTRY') 
 CREATE TABLE T_MRP_SIMULATEFIELDENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FFIELDKEY NVARCHAR(50) DEFAULT ' ' NOT NULL,
FFIELDNAME NVARCHAR(50) DEFAULT ' ' NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY1') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY1 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY2') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY2 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY3') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY3 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY4') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY4 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY5') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY5 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY6') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY6 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY7') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY7 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY8') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY8 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY9') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY9 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY10') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY10 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY11') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY11 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY12') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY12 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY13') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY13 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY14') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY14 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY15') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY15 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY16') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY16 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY17') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY17 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY18') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY18 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY19') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY19 DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_MRP_SIMULATIONDETAIL' AND KSQL_COL_NAME ='FQTY20') 
 ALTER TABLE T_MRP_SIMULATIONDETAIL ADD (FQTY20 DECIMAL(23,10) DEFAULT 0 NOT NULL );
/**End E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\MRP_table.sql **/
