/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\PUR_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_PUR_REQUESTASENTRY') 
 CREATE TABLE T_PUR_REQUESTASENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ BIGINT DEFAULT 0 NOT NULL,
FAFSERVICEBILLID BIGINT DEFAULT 0 NOT NULL
);


 EXEC p_AlterColumn 'T_PUR_REQUESTENTRY_A', 'FRETURNTYPE', 'VARCHAR(10)', 'NOT NULL', '1111', ''' ''';

 EXEC p_AlterColumn 'T_PUR_REQUESTENTRY_A', 'FSHOPRETTYPE', 'VARCHAR(10)', 'NOT NULL', '1111', ''' ''';

IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_REQUESTENTRY_A' AND KSQL_COL_NAME ='FPICKWARETYPE') 
 ALTER TABLE T_PUR_REQUESTENTRY_A ADD (FPICKWARETYPE VARCHAR(10) DEFAULT ' ' NOT NULL );
 
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_ORDCHANGENTRY_A' AND KSQL_COL_NAME ='FTAXRATEIDOLD') 
 ALTER TABLE T_PUR_ORDCHANGENTRY_A ADD (FTAXRATEIDOLD BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_ORDCHANGENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_ORDCHANGENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_CHECKENTRY2' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_CHECKENTRY2 ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_INVOICENTRY2' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_INVOICENTRY2 ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_INVOICENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_INVOICENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_RETURNENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_RETURNENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_INSTOCKENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_INSTOCKENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_SALRETURNENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_SALRETURNENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_CHECKENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_CHECKENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_ORDERCHECK' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_ORDERCHECK ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_ORDERENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_ORDERENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_REQUESTENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_REQUESTENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_RECEIPTENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_RECEIPTENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_PUR_SALOUTSTOCKENTRY' AND KSQL_COL_NAME ='FTAXRATEID') 
 ALTER TABLE T_PUR_SALOUTSTOCKENTRY ADD (FTAXRATEID BIGINT DEFAULT 0 NOT NULL );

  EXEC p_AlterColumn 'T_PUR_ORDCHANGE_L', 'FREMARK', 'NVARCHAR(512)', 'NOT NULL', '0100', ''' ''';

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