/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\SM_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SM_RETURNAPPLYENTRY_R') 
 CREATE TABLE T_SM_RETURNAPPLYENTRY_R (
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FID BIGINT DEFAULT 0 NOT NULL,
FINSPECTORGID BIGINT DEFAULT 0 NOT NULL,
FISINSPECT CHAR(1) DEFAULT '0' NOT NULL,
FINSPECTREQUESTED CHAR(1) DEFAULT '0' NOT NULL,
FPRODUCTTYPE VARCHAR(10) DEFAULT 'standard' NOT NULL,
FKITPRODUCTID BIGINT DEFAULT 0 NOT NULL,
FKITQTY DECIMAL(23,10) DEFAULT 0 NOT NULL,
FPRICEMODEL VARCHAR(10) DEFAULT ' ' NOT NULL,
FKITTRANSFERMODEL VARCHAR(10) DEFAULT ' ' NOT NULL,
FPID BIGINT DEFAULT 0 NOT NULL
);


IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_SM_XSALORDER_R') 
 CREATE TABLE T_SM_XSALORDER_R (
FID BIGINT DEFAULT 0 NOT NULL,
FCHANGECANCELSTATUS VARCHAR(5) DEFAULT ' ' NOT NULL,
FCHANGECANCELER BIGINT DEFAULT 0 NOT NULL,
FCHANGECANCELDATE DATETIME
);

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FINSPECTORGID')
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FINSPECTORGID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FISINSPECT')
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FISINSPECT CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FPRODUCTTYPE')
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FPRODUCTTYPE VARCHAR(10) DEFAULT 'standard' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FKITPRODUCTID')
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FKITPRODUCTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FKITQTY')
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FKITQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FPRICEMODEL')
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FPRICEMODEL VARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FKITTRANSFERMODEL')
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FKITTRANSFERMODEL VARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_DELIVERNOTICEENTRY_R' AND KSQL_COL_NAME ='FPID')
 ALTER TABLE T_SM_DELIVERNOTICEENTRY_R ADD (FPID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_SALORDERENTRY_R' AND KSQL_COL_NAME ='FPRODUCTTYPE')
 ALTER TABLE T_SM_SALORDERENTRY_R ADD (FPRODUCTTYPE VARCHAR(10) DEFAULT 'standard' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_SALORDERENTRY_R' AND KSQL_COL_NAME ='FKITPRODUCTID')
 ALTER TABLE T_SM_SALORDERENTRY_R ADD (FKITPRODUCTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_SALORDERENTRY_R' AND KSQL_COL_NAME ='FKITQTY')
 ALTER TABLE T_SM_SALORDERENTRY_R ADD (FKITQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_SALORDERENTRY_R' AND KSQL_COL_NAME ='FPRICEMODEL')
 ALTER TABLE T_SM_SALORDERENTRY_R ADD (FPRICEMODEL VARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_SALORDERENTRY_R' AND KSQL_COL_NAME ='FKITTRANSFERMODEL')
 ALTER TABLE T_SM_SALORDERENTRY_R ADD (FKITTRANSFERMODEL VARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_SALORDERENTRY_R' AND KSQL_COL_NAME ='FPID')
 ALTER TABLE T_SM_SALORDERENTRY_R ADD (FPID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FPRODUCTTYPE')
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FPRODUCTTYPE VARCHAR(10) DEFAULT 'standard' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FKITPRODUCTID')
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FKITPRODUCTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FKITQTY')
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FKITQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FPRICEMODEL')
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FPRICEMODEL VARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FKITTRANSFERMODEL')
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FKITTRANSFERMODEL VARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_XSALORDERENTRY_R' AND KSQL_COL_NAME ='FPID')
 ALTER TABLE T_SM_XSALORDERENTRY_R ADD (FPID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_QUOTATIONENTRY' AND KSQL_COL_NAME ='FPRODUCTTYPE')
 ALTER TABLE T_SM_QUOTATIONENTRY ADD (FPRODUCTTYPE VARCHAR(10) DEFAULT 'standard' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_QUOTATIONENTRY' AND KSQL_COL_NAME ='FKITPRODUCTID')
 ALTER TABLE T_SM_QUOTATIONENTRY ADD (FKITPRODUCTID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_QUOTATIONENTRY' AND KSQL_COL_NAME ='FKITQTY')
 ALTER TABLE T_SM_QUOTATIONENTRY ADD (FKITQTY DECIMAL(23,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_QUOTATIONENTRY' AND KSQL_COL_NAME ='FPRICEMODEL')
 ALTER TABLE T_SM_QUOTATIONENTRY ADD (FPRICEMODEL VARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_QUOTATIONENTRY' AND KSQL_COL_NAME ='FKITTRANSFERMODEL')
 ALTER TABLE T_SM_QUOTATIONENTRY ADD (FKITTRANSFERMODEL VARCHAR(10) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_SM_QUOTATIONENTRY' AND KSQL_COL_NAME ='FPID')
 ALTER TABLE T_SM_QUOTATIONENTRY ADD (FPID BIGINT DEFAULT 0 NOT NULL );

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