/**Begin E:\NextERP_PDM\PDM_UPGRADE\PDMS\branch_lastest\pdm\CAS_table.sql **/
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_BANKSTATEMENT' AND KSQL_COL_NAME ='FRATESDATE') 
 ALTER TABLE T_CAS_BANKSTATEMENT ADD (FRATESDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_RECBILLCHANG_E' AND KSQL_COL_NAME ='FPAYERNUMBER') 
 ALTER TABLE T_CAS_RECBILLCHANG_E ADD (FPAYERNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_RECBILLCHANG_E' AND KSQL_COL_NAME ='FISUNCLAIM') 
 ALTER TABLE T_CAS_RECBILLCHANG_E ADD (FISUNCLAIM CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL' AND KSQL_COL_NAME ='FUNIFORMSOCIALCREDITCODE') 
 ALTER TABLE T_CAS_PAYMENTBILL ADD (FUNIFORMSOCIALCREDITCODE VARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL' AND KSQL_COL_NAME ='FPAYERNUMBER') 
 ALTER TABLE T_CAS_PAYMENTBILL ADD (FPAYERNUMBER VARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL' AND KSQL_COL_NAME ='FPAYEENUMBER') 
 ALTER TABLE T_CAS_PAYMENTBILL ADD (FPAYEENUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL' AND KSQL_COL_NAME ='FPRIORITY') 
 ALTER TABLE T_CAS_PAYMENTBILL ADD (FPRIORITY VARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYMENTBILL' AND KSQL_COL_NAME ='FISTOP') 
 ALTER TABLE T_CAS_PAYMENTBILL ADD (FISTOP CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CASHJOURNAL' AND KSQL_COL_NAME ='FAVDDATE') 
 ALTER TABLE T_CAS_CASHJOURNAL ADD (FAVDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CASHJOURNAL' AND KSQL_COL_NAME ='FPDDATE') 
 ALTER TABLE T_CAS_CASHJOURNAL ADD (FPDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CASHJOURNAL' AND KSQL_COL_NAME ='FFEEPAYER') 
 ALTER TABLE T_CAS_CASHJOURNAL ADD (FFEEPAYER NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CASHJOURNAL' AND KSQL_COL_NAME ='FPREPARATIONDATE') 
 ALTER TABLE T_CAS_CASHJOURNAL ADD (FPREPARATIONDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_RECEIVINGBILL_E' AND KSQL_COL_NAME ='FPAYERNUMBER') 
 ALTER TABLE T_CAS_RECEIVINGBILL_E ADD (FPAYERNUMBER NVARCHAR(255) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_RECEIVINGBILL_E' AND KSQL_COL_NAME ='FISUNCLAIM') 
 ALTER TABLE T_CAS_RECEIVINGBILL_E ADD (FISUNCLAIM CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FPDDATE') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FPDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FAVDDATE') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FAVDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FSYSDATE') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FSYSDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FSETTLEMENTTYPE') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FSETTLEMENTTYPE BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FOPPACCTNUMBER') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FOPPACCTNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FBALANCEAMT') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FBALANCEAMT DECIMAL(20,10) DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FSOURCEBILLNUMBER') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FSOURCEBILLNUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FTRADENUMBER') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FTRADENUMBER NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FBANKVOUVHERNO') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FBANKVOUVHERNO NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FISCHECK') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FISCHECK CHAR(1) DEFAULT '1' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FSOURCE') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FSOURCE NVARCHAR(50) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_CHECKEDRESULTENTRY' AND KSQL_COL_NAME ='FCASHIER') 
 ALTER TABLE T_CAS_CHECKEDRESULTENTRY ADD (FCASHIER BIGINT DEFAULT 0 NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_BANKJOURNAL' AND KSQL_COL_NAME ='FAVDDATE') 
 ALTER TABLE T_CAS_BANKJOURNAL ADD (FAVDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_BANKJOURNAL' AND KSQL_COL_NAME ='FPDDATE') 
 ALTER TABLE T_CAS_BANKJOURNAL ADD (FPDDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_BANKJOURNAL' AND KSQL_COL_NAME ='FFEEPAYER') 
 ALTER TABLE T_CAS_BANKJOURNAL ADD (FFEEPAYER NVARCHAR(30) DEFAULT ' ' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_BANKJOURNAL' AND KSQL_COL_NAME ='FPREPARATIONDATE') 
 ALTER TABLE T_CAS_BANKJOURNAL ADD (FPREPARATIONDATE DATETIME );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERCOLUMNS WHERE KSQL_COL_TABNAME = 'T_CAS_PAYCHGBILL' AND KSQL_COL_NAME ='FISCASHCONFIRM') 
 ALTER TABLE T_CAS_PAYCHGBILL ADD (FISCASHCONFIRM CHAR(1) DEFAULT '0' NOT NULL );
IF NOT EXISTS (SELECT 1 FROM KSQL_USERTABLES WHERE KSQL_TABNAME = 'T_CAS_RECEIVINGINFOENTRY') 
 CREATE TABLE T_CAS_RECEIVINGINFOENTRY (
FID BIGINT DEFAULT 0 NOT NULL,
FENTRYID BIGINT DEFAULT 0 NOT NULL,
FSEQ INT DEFAULT 0 NOT NULL,
FCDMDRAFTBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FCDMCURRENCY BIGINT DEFAULT 0 NOT NULL,
FCDMAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBEIBILLNO NVARCHAR(50) DEFAULT ' ' NOT NULL,
FBEICURRENCY BIGINT DEFAULT 0 NOT NULL,
FBEICREDITAMOUNT DECIMAL(19,6) DEFAULT 0 NOT NULL,
FBEIDETAILID NVARCHAR(50) DEFAULT ' ' NOT NULL,
FINFOID BIGINT DEFAULT 0 NOT NULL
);


 EXEC p_AlterColumn 'T_CAS_RECEIVINGBILL', 'FSETTLETNUMBER', 'NVARCHAR(255)', 'NOT NULL', '0100', ''' ''';

 EXEC p_AlterColumn 'T_CAS_RECBILLCHANG', 'FSETTLETNUMBER', 'NVARCHAR(255)', 'NOT NULL', '0100', ''' ''';


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